Notion API for Laravel
Published on by Paul Redmond
Notion API for Laravel is a package to effortlessly create Notion integrations with Laravel:
This package provides a simple and crisp way to access the Notion API endpoints, query data, and update existing entries.
The package includes convenient methods to fetch page information, search Notion collection pages and databases in your workspace:
- Fetch a Notion page
- Fetch children from a specific block
- Search all databases and pages
- Get all pages in a workspace
- Fetch all databases of a workspace
Here’s some usage examples from the API documentation:
// Returns a specific page$notion->pages()->find($yourPageId); // Returns all pages of the workspace\Notion::search() ->onlyPages() ->query() ->asCollection(); // Returns all databases of the workspace\Notion::search() ->onlyDatabases() ->query() ->asCollection(); // Fetches all users from this workspace\Notion::users() ->limit(5) // limit is optional ->all() ->asCollection(); // Retrieves data for a specific user in this workspace\Notion::users() ->find($userId);
More specifically, here are some examples of retrieving properties from a specific page:
// Access properties from a specific page$page = \Notion::pages() ->find($pageId); // Returns all properties as collection$page->getProperties(); // Returns specific property by propertyKey$page->getProperty($propertyKey); // Returns specific property content by propertyKey (returned type depends on the property-type)$page->getProperty($propertyKey)->getContent(); // Returns specific property content by propertyKey (array of exact NotionApi-structure is returned)$page->getProperty($propertyKey)->getRawContent(); // Returns array of propertyKeys (names/titles of properties)$page->getPropertyKeys(); // Return json-array of all properties$page->getRawProperties();
Learn More
You can see the source code, get installation instructions, and get installation instructions on GitHub at 5am-code/laravel-notion-api. The official documentation has more code examples and usage details. You can learn more about the Notion API at developers.notion.com.