If you have any questions or feedback, feel free to @ someone of the team on Twitter, create an issue or open a pull request yourself! :)
use FiveamCode\LaravelNotionApi\Notion;
use Illuminate\Support\Collection;
use FiveamCode\LaravelNotionApi\Query\Sorting;
use FiveamCode\LaravelNotionApi\Query\Filter;
// Setup basic API connection
$notion = new Notion();
$notion->v1();
// Fetches children from a specific block
$notion
->block($blockId)
->limit(1) // limit is optional
->children();
// Queries a specific database and returns a collection of pages (= database entries)
$sortings = new Collection();
$filters = new Collection();
$sortings
->add(Sorting::propertySort("Ordered", "ascending"));
$sortings
->add(Sorting::timestampSort("created_time", "ascending"));
$filters
->add(
Filter::textFilter(
"title",
["contains" => "new"]
)
);
// or
$filters
->add(
Filter::rawFilter(
"Tags",
[
"multi_select" =>
["contains" => "great"]
]
)
);
// the whole query
$notion
->database("f2929743f6944ce2b613f28db6ded673")
->filterBy($filters) // filters are optional
->sortBy($sortings) // sorts are optional
->limit(5) // limit is optional
->query();
⚡ Watch out: This endpoint is no longer recommended by Notion and can be removed anytime.
// This endpoint is not recommended by Notion anymore but is working nevertheless.
// Use the search endpoint instead - as soon as it's implemented ;)
// Returns all databases of the workspace that were explicitly granted access.
$notion
->databases()
->all();
// Returns a single database
$notion
->databases()
->find($databaseId);
// Returns a specific page
$notion
->pages()
->find($pageId);
// Returns the title of a specific page
$notion
->pages()
->find($pageId)
->getTitle()
// Access properties from a specific page
$page = $notion
->pages()
->find($pageId);
// Returns all properties as collection
$page->getProperites();
// Returns specific property by propertyName
$page->getProperty($propertyName);
// Return json-array of all properties
$page->getRawProperties();
// Fetches all users from this workspace
$notion
->users()
->limit(5) // limit is optional
->all();
// Retrieves data for a specific user in this workspace
$notion
->users()
->find($userId);