splitbee/notion-api-worker

Feature request: add search proxy

transitive-bullshit opened this issue · 0 comments

Something like POST /v1/search:

export interface SearchParams {
  query: string
  ancestorId: string
  limit?: number
}

export async function search(params: SearchParams) {
  const body = {
    type: 'BlocksInAncestor',
    source: 'quick_find_public',
    ancestorId: params.ancestorId,
    filters: {
      isDeletedOnly: false,
      excludeTemplates: true,
      isNavigableOnly: true,
      requireEditPermissions: false,
      ancestors: [],
      createdBy: [],
      editedBy: [],
      lastEditedTime: {},
      createdTime: {}
    },
    sort: 'Relevance',
    limit: params.limit || 20,
    query: params.query
  }

  return fetch('https://www.notion.so/api/v3/search', {
    method: 'POST',
    headers: {
      'content-type': 'application/json'
    },
    body: JSON.stringify(body)
  }).then((res) => res.json())
}

This is necessary to get around CORS from the client-side.