Skip to content

serversidesquid/laravel-notion-api

 
 

Repository files navigation

Laravel Notion API

Effortless Notion integrations with Laravel

Latest Version on Packagist Total Downloads

This package provides a simple and crisp way to access the Notion API endpoints, query data and update existing entries.

Installation

You can install the package via composer:

composer require fiveam-code/laravel-notion-api

Authorization

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 the API access.

Add your Notion API token to your .env file:

NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"

Usage

Head over to the Documentation of this package.

🔥 Code Examples to jumpstart your Notion API Project

Basic Setup (+ example)

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 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();

Testing

vendor/bin/phpunit tests

Changelog

Please see CHANGELOG for more information what has changed recently.

References / UsedBy

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

About

Effortless Notion integrations with Laravel

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%