Picture of the author

Notion Databases

Fetch Database Structure

Fetch database by ID

This endpoint fetches one database and provides all structural information about it.

$database = Notion::databases()->find($databaseId);

Database information

# Get database title and description
$database->getTitle();
$database->getDescription();

# Get database icon and icon-type (emoji, file, external)
$database->getIcon();
$database->getIconType();

# Get database cover and cover-type (file, external)
$database->getCover();
$database->getCoverType();

# Get database url (within Notion)
$database->getUrl();

# Check if database is inline
$database->isInline();

Properties of a Database

Get property information of the database by calling getProperties(). This will return a Collection with objects inheriting Property::class, which include structural information about each Property. Please be aware: This is only the structural representation of the Property, no content is provided here.

The method getPropertyKeys() returns an array of all property keys (= property names).

# `Collection` of objects inheriting `Property::class`
$collectionOfProperties = $database->getProperties();

# Get all keys of the properties (property names)
$arrayOfPropertyNames = $database->getPropertyKeys();

Raw Database Structure

This is an example of a Notion database raw structure. Please check Handling Results on how to retreive raw data.

{
  "object": "database",
  "id": "bc1211ca-e3f1-4939-ae34-5260b16f627c",
  "created_time": "2021-07-08T23:50:00.000Z",
  "last_edited_time": "2021-07-08T23:50:00.000Z",
  "icon": {
    "type": "emoji",
    "emoji": "🎉"
  },
  "cover": {
    "type": "external",
    "external": {
      "url": "https://website.domain/images/image.png"
    }
  },
  "url": "https://www.notion.so/bc1211cae3f14939ae34260b16f627c",
  "title": [
    {
      "type": "text",
      "text": {
        "content": "Grocery List",
        "link": null
      },
      "annotations": {
        "bold": false,
        "italic": false,
        "strikethrough": false,
        "underline": false,
        "code": false,
        "color": "default"
      },
      "plain_text": "Grocery List",
      "href": null
    }
  ],
  "description": [
    {
      "type": "text",
      "text": {
        "content": "Grocery list for just kale 🥬",
        "link": null
      },
      "annotations": {
        "bold": false,
        "italic": false,
        "strikethrough": false,
        "underline": false,
        "code": false,
        "color": "default"
      },
      "plain_text": "Grocery list for just kale 🥬",
      "href": null
    }
  ],
  "properties": {
    "Name": {
      "id": "title",
      "name": "Name",
      "type": "title",
      "title": {}
    }
  },
  "parent": {
    "type": "page_id",
    "page_id": "98ad959b-2b6a-4774-80ee-00246fb0ea9b"
  },
  "archived": false,
  "is_inline": false
}

Source: Example from Notion API Docs (in parts) ( Retrieve a database )

Fetch all Databases [Deprecated]

Endpoint 'Fetch all Databases' is Deprecated

This endpoint is no longer recommended by Notion and can be removed anytime. It is recommended to use Search Notion Content instead.

# Returns all databases of the workspace that were explicitly granted access.
Notion::databases()
        ->all()
        ->asCollection();
Previous
Fetching Users