pythonjsonnotion-apinotion

Updating multiple entries in a notion database with API


I have a notion database which I call with the API like so:

url = f"https://api.notion.com/v1/databases/{NotionDB}/query"
payload = {"page_size": 200}
headers = { "Authorization": NotionKEY,
            "accept": "application/json",
            "Notion-Version": "2022-06-28",
            "content-type": "application/json"
        }
response = requests.post(url, json=payload, headers=headers)
data = json.loads(response.text)

This returns a data['results'] with the following structure:

[{'object': 'page',
  'id': 'ABC'
  ....
  'parent': {'type': 'database_id',
   'database_id': 'XXXXX'},
  'archived': False,
  'properties': {'Prop 1': {'id': '%40QKL',
   ....}},
  'url': 'https://www.notion.so/XYZ'},
 {'object': 'page',
  'id': 'CDE',
  'parent': {'type': 'database_id',
   'database_id': 'XXXXX'},
  'archived': False,
  'properties': {'Prop 1': {'id': '%40QKL',
    ..... }},
  'url': 'https://www.notion.so/ABCD'},
{'object': etc}, '{'object': etc}]

so, a list of objects, each of which seems to be a page. My goal is to make some changes to the properties of those objects and then update the database.

I am able to do so looping over each individual page. After editing the list of jsons, I do:

url = "https://api.notion.com/v1/pages/ID-OF-i_th-PAGE"
payload = {"properties": data['results'][i]['properties']}
headers = {
     "Authorization": NotionKEY,
    "accept": "application/json",
    "Notion-Version": "2022-06-28",
    "content-type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)

which works. This however implies doing N API calls, if my list has N elements. Is there a way to directly update the properties of the database elements in a single call?


Solution

  • According to Notion support this is not possible. The feature has been requested but is not available on Oct. 20th 2022.