-1

I don't understand why a simple fetch request is unsuccessful via Vanilla JS but successful via Postman:

Insomia

const getNotion = () => {
  fetch(
    "https://api.notion.com/v1/databases/[DBID_HERE]",
    {
      method: "GET",
      headers: {
        "Authorization": "Bearer [SECRET_HERE]",
        "Notion-Version": "2021-05-11"
      }
    }
  )
    .then((response) => response.json())
    .then((json) => {
      console.log(json);
    })
    .catch((err) => console.log("Request Failed", err));
};

getNotion();

The response is Request Failed TypeError: Failed to fetch. Both DBID and SECRET are correct.

Ben
  • 345
  • 2
  • 4
  • 13

1 Answers1

1

Notion API doesn't support CORS (if you want you could learn more about it). And also in case you want your site to go online you really should not call APIs from your website because it will public your credentials. So the easiest solution for me who doesn't want to spend much time on BE is to use serverless functions.

soahyle
  • 21
  • 2