Skip to content

5am-code/laravel-notion-api

 
 

Repository files navigation

Notion for 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

  1. You can install the package via composer:

    composer require fiveam-code/laravel-notion-api
  2. Get your Notion API access token like explained in their documentation. It's also important to grant access to the integration within your Notion pages, which is described in the developer documentation at Notion as well.

  3. For internal Integrations, please add a new entry to your .env like the following:

    NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"
  4. Now you can easily access Notion:

    use \Notion;
    
    Notion::databases()->find($databaseId);

    That's it.

Usage

Head over to the Documentation of this package.

🔥 Code Examples to jumpstart your next Notion API Project

Fetch a Notion Database (through a Facade)

use \Notion; 

Notion::databases()
        ->find("a7e5e47d-23ca-463b-9750-eb07ca7115e4");

Fetch a Notion Page

Notion::pages()
        ->find("e7e5e47d-23ca-463b-9750-eb07ca7115e4");

Search

// Returns a collection pages and databases of your workspace (included in your integration-token)
Notion::search("My Notion Search")
        ->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("a7e5e47d-23ca-463b-9750-eb07ca7115e4")
      ->filterBy($filters) // filters are optional
      ->sortBy($sortings) // sorts are optional
      ->limit(5) // limit is optional
      ->query()
      ->asCollection();

Testing (pestphp)

vendor/bin/pest tests

Support

If you use this package in one of your projects or just want to support our development, consider becoming a Patreon!

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email hello@dianaweb.dev instead of using the issue tracker.

Credits

License

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

Sponsor this project

Contributors 12

Languages