6

I want to use Notion as a content gateway for a SPA. Can I use the Notion API from fetch? I'm trying to use fetch to get the data but It's not working because of CORS.

let notion = fetch(import.meta.env.VITE_NOTION_API_URL+'/databases/'+import.meta.env.VITE_NOTION_APP_DATABASE+'/query', {
      method: 'POST',
      mode: 'cors',
      credentials: 'omit',
      headers: {
        'Content-Type': 'application/json',
        "Authorization": `Bearer ${import.meta.env.VITE_NOTION_API_SECRET}`,
        "Notion-Version": `${import.meta.env.VITE_NOTION_API_VERSION}`,
      }
    })

It's this possible?

picsoung
  • 6,314
  • 1
  • 18
  • 35
Ricardo Vargas
  • 721
  • 4
  • 14

1 Answers1

8

No. The Notion API does not support CORS.

adlopez15
  • 3,449
  • 2
  • 14
  • 19
  • Thanks for the reply @adlopez15. – Ricardo Vargas Jun 23 '21 at 20:59
  • 1
    It's crazy how long it took me to discover this critical piece of information. Is this stated somewhere or do you just happen to know it for a fact @adlopez15? – T3db0t Jul 20 '21 at 17:27
  • `We currently don't support CORS and don't recommend making API calls from a web page.` https://github.com/makenotion/notion-sdk-js/issues/96 – ksav Aug 14 '21 at 08:03
  • Technically it is possible to use a server side `fetch` implementation like `undici` or `node-fetch`. – Nick McCurdy Jul 31 '22 at 08:05