14
SepLaravel Notion API is an awesome package that provides a simple and crisp way to access the Notion API endpoints, query data, and update existing entries.
You can install the package via composer:
composer require fiveam-code/laravel-notion-api
The Notion API requires an access token and a Notion integration, the Notion documentation explains how this works. It’s important to grant access to the integration within your Notion account to enable API access.
Add your Notion API token to your .env file:
NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
Setup
use FiveamCode\LaravelNotionApi\Notion;
# Access through Facade (token has to be set in .env)
\Notion::databases()->find($databaseId);
# Custom instantiation (necessary if you want to access more than one NotionApi integration)
$notion = new Notion($apiToken, $apiVersion); // version-default is 'v1'
$notion->databases()->find($databaseId);
Fetch Page Information
// Returns a specific page
\Notion::pages()->find($yourPageId);
Search
// Returns a collection of pages and databases of your workspace (included in your integration-token)
\Notion::search($searchText)
->query()
->asCollection();
Query Database
// 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']]));
\Notion::database($yourDatabaseId)
->filterBy($filters) // filters are optional
->sortBy($sortings) // sorts are optional
->limit(5) // limit is optional
->query()
->asCollection();
For more details, please head over to the documentation.
If you are a business and want to leverage Laravel for your next PHP-based web application, CRM Software, E-commerce application, SAAS application, or any custom web application development for your custom requirements, you must discover an amazing team with experience in the Laravel framework. So Codebrisk is here to help you with your tailored requirements regarding Laravel Development. Please feel free to send us an email at rizwan@codebrisk.com or get in touch with us, our business person will get back to you.
Published at : 14-09-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project