Picture of the author

Basics

Content Search

Basic Query

Query all connected databases and pages of a Notion workspace, based on a search string. The maximum amount of entries which can be queried is 100.

$search = 'search term';

Notion::search($search) // if NULL, all entries are returned
        ->query()
        ->asCollection();

Force Pages or Databases

If you want to constrain the search result to Pages or Databases only, you can do so by forcing the result by the methods onlyPages() or onlyDatabases().

# Limit to pages
Notion::search()
        ->onlyPages()
        ->query()
        ->asCollection();

# Limit to databases
Notion::search()
        ->onlyDatabases()
        ->query()
        ->asCollection();

Limit Search Results

Limit the number of search results with limit(...).

Notion::search()
        ->query()
        ->limit(10) // limit to 10 results
        ->asCollection();

Sort by LastEditedTime

By default, the results are sorted by the LastEditedTime from latest to oldest. If the oldest is supposed to appear as the first entry, it's possible to force the sort order.

$direction = 'ascending'; // or 'descending'

Notion::search()
        ->sortByLastEditedTime($direction)
        ->query()
        ->asCollection();

Get Results as JSON

To simplify the frontend-handling (e.g. Vue, React, etc.) of results, it's possible to get the results as JSON.

Notion::search()
        ->query()
        ->asJson();
Previous
Upgrade Guide