splitbee / notion-api-worker

Notion as CMS with easy API access
MIT License
1.56k stars 197 forks source link

Feature request: add search proxy #14

Closed transitive-bullshit closed 4 years ago

transitive-bullshit commented 4 years ago

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.