Hey everyone, I’m stuck with a Notion API problem. I’m trying to set up a public integration, but I keep getting this ‘Missing or invalid redirect_uri’ error. It’s driving me nuts!
Here’s what I’ve got in my index.html:
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Notion API Test</title>
</head>
<body>
<a href="https://api.notion.com/v1/oauth/authorize?client_id=d8e20155-937a-412d-ac99-f3bf9458dd64&redirect_uri=https%3A%2F%2Fmy-notion-app.herokuapp.com%2Fauth%2Fcallback&response_type=code">
Connect to Notion
</a>
</body>
</html>
And here’s my backend setup:
app.get("/auth/callback/:code/:state", (req, res) => {
let authCode = req.params.code;
let authState = req.params.state;
console.log(authCode);
res.json({
"status": "Auth callback received",
"code": authCode,
"state": authState
});
axios.post('https://api.notion.com/v1/oauth/token', {
grant_type: "authorization_code",
code: authCode,
redirect_uri: 'https://my-notion-app.herokuapp.com/auth/callback/'
}).then((response) => {
console.log(response)
}).catch((error) => {
console.log(`Error:`, error);
})
});
I’ve set the redirect URI in my integration settings to ‘https://my-notion-app.herokuapp.com/’. The GET request isn’t firing though. I checked the Heroku logs. Any ideas what I’m doing wrong with the redirect URI? Help!
I’ve been down this road before, and it can be quite frustrating. From what I see, there’s a subtle issue with how you’re handling the callback. Your backend route is expecting parameters in the URL path, but OAuth typically sends these as query parameters.
Try updating your Express route like this:
app.get('/auth/callback', (req, res) => {
const authCode = req.query.code;
const authState = req.query.state;
// ... rest of your code
});
Also, make sure your redirect URI in the Notion integration settings matches exactly: ‘https://my-notion-app.herokuapp.com/auth/callback’ (no trailing slash).
One last thing - double-check that your client_id in the authorization URL is correct. Sometimes it’s easy to overlook, but it can cause this error too.
If you’re still stuck after trying these, let me know and we can dig deeper.
I’ve encountered this issue before. The problem likely stems from a mismatch between the redirect URI you’ve specified in different places. First, ensure the redirect URI in your Notion integration settings matches exactly what you’re using in your code. Additionally, your backend route doesn’t seem to match the URI structure you’re using. Try modifying your Express route to:
app.get(‘/auth/callback’, (req, res) => {
const authCode = req.query.code;
const authState = req.query.state;
// Rest of your code…
});
This should align with the redirect URI you’re using in the authorization URL. Remember, consistency is key when dealing with OAuth flows. Let me know if you need further clarification.
hey there FlyingEagle! looks like ur redirect_uri in the auth URL doesn’t match the one in ur backend. Try changing the backend redirect_uri to ‘https://my-notion-app.herokuapp.com/auth/callback’ (without the trailing slash). also, make sure this exact URI is listed in ur Notion integration settings. hope that helps!