Examples

If you have any questions or feedback, feel free to @ someone of the team on Twitter, create an issue or open a pull request yourself! :)

Setup API-Connection

use FiveamCode\LaravelNotionApi\Notion;
use Illuminate\Support\Collection;
use FiveamCode\LaravelNotionApi\Query\Sorting;
use FiveamCode\LaravelNotionApi\Query\Filter;

// Setup basic API connection
$notion = new Notion();
$notion->v1();

Blocks

// Fetches children from a specific block
$notion
     ->block($blockId)
     ->limit(1) // limit is optional
     ->children();

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"]
            ]
        )
    );

// the whole query
$notion
    ->database("f2929743f6944ce2b613f28db6ded673")
    ->filterBy($filters) // filters are optional
    ->sortBy($sortings) // sorts are optional
    ->limit(5) // limit is optional
    ->query(); 

Database(s)

⚡ Watch out: This endpoint is no longer recommended by Notion and can be removed anytime.

// This endpoint is not recommended by Notion anymore but is working nevertheless. 
// Use the search endpoint instead - as soon as it's implemented ;)

// Returns all databases of the workspace that were explicitly granted access.
$notion
    ->databases()
    ->all();

// Returns a single database
$notion
    ->databases()
    ->find($databaseId);

Pages

// Returns a specific page
$notion
    ->pages()
    ->find($pageId);

User(s)

// Fetches all users from this workspace
$notion
    ->users()
    ->limit(5) // limit is optional
    ->all();

// Retrieves data for a specific user in this workspace
$notion
    ->users()
    ->find($userId);