Closed1

Query 100 over records from Notion, by Python, in Pipedream

hirogahiroga

TL;DR

import random
import requests

database_id = "YOUR_DATABASE_ID_HERE"
query_payload = {
  "filter": {}, # YOUR_FILTER_HERE
  "sorts": []
}

def handler(pd: "pipedream"):
  token = pd.inputs["notion"]["$auth"]["oauth_access_token"]
  authorization = f'Bearer {token}'
  headers = {"Authorization": authorization, "Notion-Version": '2021-08-16', "Content-Type": "application/json"}

  def query_all_records(url, payload, start_cursor=None):
    if start_cursor:
      payload['start_cursor'] = start_cursor
    r = requests.post(url, headers=headers, json=payload)
    data = r.json()
    print(data)
    if 'next_cursor' in data and data['next_cursor'] is not None:
      data['results'].extend(query_all_records(url, payload, data['next_cursor'])['results'])
    return data

  all_records = query_all_records(f'https://api.notion.com/v1/databases/6c136e2d-{database_id}/query', query_payload)

  return join(all_records)
このスクラップは2024/04/13にクローズされました