2

I am trying to access a single database in my Notion via the REST API.

When querying or listing my database in Notion, I only receive a subset of the expected properties.

There are 23 properties in my accessed database as you can see in the last screenshot. So there are 7 that are not showing up since I am seeing 16 when I call the LIST DB REST API (1st screenshot). Any idea why these 7 properties are not showing up?

   class Test:
    def __init__(self):
        self.notion = None
        self.databases = {}
        self.pageIds = []
        self.pages = {}

    def initialize(self):
        #NOTION_TOKEN = os.getenv("NOTION_TOKEN", "")
        with open('Notion_Config.YAML') as f:
            data = yaml.load(f, Loader=yaml.FullLoader)
            print(data)
        NOTION_TOKEN = data["Token"]

        while NOTION_TOKEN == "":
            print("NOTION_TOKEN not found.")
            NOTION_TOKEN = input("Enter your integration token: ").strip()

        self.notion = Client(auth=NOTION_TOKEN)

    def list_db(self):
        results = self.notion.databases.list()
        print("Listing databases: ")
        for item in results["results"]:
            print(item["title"][0]["plain_text"])
            self.databases.update({item["title"][0]["plain_text"] : item["id"]})

    def query_db(self, database_name):
        #while db["more"] == True:
        db = self.notion.databases.query(database_id=self.databases.get(database_name))
        for item in db["results"]:
            print(item)
            self.pageIds.append(item["id"])

    def query_pages(self):
        for item in self.pageIds:
            page = self.notion.pages.retrieve(page_id=item)
            print(page)

Calling list_db. You can see the number of properties retrieved is 16 Calling list_db. You can see the number of properties retrieved is 16

Calling query_db. You can see the number of properties retrieved for this first page is 14 Calling query_db. You can see the number of properties retrieved is 14

This screenshot shows the list of properties for my database

This screenshot shows the list of properties for my database

Spectrem
  • 682
  • 1
  • 11
  • 37

1 Answers1

3

The final screenshot which shows the properties of the database in notion has 6 arrows enter image description here. These 6 properties represent relational properties which point to a database.

  • Related Project
  • Shopping List
  • Dependent on (Task)
  • Related People/Company
  • Resources
  • Sub Tasks

2 of those relation properties are self relations, meaning they point to the same database where they reside.

  • Sub Tasks
  • Dependent On (Tasks)

The calls to the Notion REST API can only access databases that you have given permissions to. Since you have only provided access to this single database, then you should only see self relation properties.

The magnifying glasses enter image description here represent formula properties. If any formula property uses a relation property that your Notion API integration doesnt have access to, then you will also not be able to see those either.

  • Project State
  • Purchase State
  • Costs

When querying for pages in the database, you may only receive properties that the page has a non-empty value.

Spectrem
  • 682
  • 1
  • 11
  • 37