Notion API for Laravel

Packages

May 25th, 2021

laravel-notion-api-featured.png

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:

1// Returns a specific page
2$notion->pages()->find($yourPageId);
3 
4// Returns all pages of the workspace
5\Notion::search()
6 ->onlyPages()
7 ->query()
8 ->asCollection();
9 
10// Returns all databases of the workspace
11\Notion::search()
12 ->onlyDatabases()
13 ->query()
14 ->asCollection();
15 
16// Fetches all users from this workspace
17\Notion::users()
18 ->limit(5) // limit is optional
19 ->all()
20 ->asCollection();
21 
22// Retrieves data for a specific user in this workspace
23\Notion::users()
24 ->find($userId);

More specifically, here are some examples of retrieving properties from a specific page:

1// Access properties from a specific page
2$page = \Notion::pages()
3 ->find($pageId);
4 
5// Returns all properties as collection
6$page->getProperties();
7 
8// Returns specific property by propertyKey
9$page->getProperty($propertyKey);
10 
11// Returns specific property content by propertyKey (returned type depends on the property-type)
12$page->getProperty($propertyKey)->getContent();
13 
14// Returns specific property content by propertyKey (array of exact NotionApi-structure is returned)
15$page->getProperty($propertyKey)->getRawContent();
16 
17// Returns array of propertyKeys (names/titles of properties)
18$page->getPropertyKeys();
19 
20// Return json-array of all properties
21$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.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.