How to read database, page and blocks - examples? #156
-
Hi there. I see the potential of this SDK and appreciate its development very much, so thank you. I have a hard time of getting it up and running unfortunately. The documentation looks very focused on adding and creating to Notion - not reading or querying. Connection with Notion works fine and print_r() of any of the results shows me the objects loaded correctly from Notion. I'm just having a really hard time showing the results because I the only example I found about reading and displaying from Notion was this article: https://mario.engineering/notion-sdk-php/how-to/query-database.html More examples of how to filter Status="Published" and show database, page results or full block results from a page would really help me. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Hi @thysroes, thanks for using the SDK! Status filterRegarding the status filter, I will update it to make it easier to understand. To address the <?php
use Notion\Notion;
use Notion\Databases\Query;
use Notion\Databases\Query\StatusFilter;
$token = $_ENV["NOTION_SECRET"];
$notion = Notion::create($token);
$databaseId = "c986d7b0-7051-4f18-b165-cc0b9503ffc2";
$database = $notion->databases()->find($databaseId);
$query = Query::create()->changeFilter(
StatusFilter::property("Status")->equals("Published"),
);
$result = $notion->databases()->query($database, $query);
$pages = $result->pages; // filtered pages QueryAllPages errorAbout the error while querying all pages, this is probably an SDK error. Could you help me with a little bit of information so I can debug and solve this issue?
Displaying from NotionI am unsure if I understood what you mean by "Displaying from Notion". With the SDK and the Notion API, you can read and write data from/to Notion. Getting to display the content from Notion in another place is out of the scope of the API. |
Beta Was this translation helpful? Give feedback.
-
Thank you, that works! ChatGPT helped me get to the PlainText title like: |
Beta Was this translation helpful? Give feedback.
Hi @thysroes, thanks for using the SDK!
Status filter
Regarding the status filter, I will update it to make it easier to understand.
To address the
Status=Published
filter, you could try the following:QueryAllPages error
…