After I got the temporary code, I send it to exchange access token, but it returns 401 unauthorized error. Here is my code:
const resp = await fetch("https://api.notion.com/v1/oauth/token", { method:'POST',
client_id: notionClientId, client_secret: notionClientSecret,
headers: { "Content-Type": "application/json" },
data: { code, grant_type: "authorization_code"} })
What's wrong here?. There is no much information in Notion documentation.
Edit: i am using localhost as my redirect URL in the integration setup.
@Nithur:
I went through this process a while ago. I'd recommend running this process via Postman. There you can setup everything easily, refer Notion's Authorization documentation. After reviewing your snippet, I believe you are not forming your POST request properly.
If you still want to set this on your project, here's a snippet that may help you using JavaScript Fetch:
If you want to try it out from Postman replacing the values with your own, import this cURL snippet as raw text: