Encountering 'Missing or invalid redirect_uri' error during Notion API integration authorization

Using a public API integration with Notion, I encounter a ‘Missing or invalid redirect_uri’ error. The provided HTML link and backend route seem misconfigured. See examples below:

<html>
  <head>
    <meta charset="utf-8">
    <title>Integration Test</title>
  </head>
  <body>
    <a href="https://api.notion.com/v1/oauth/authorize?client_id=NEW_CLIENT&redirect_uri=https%3A%2F%2Fexample-app.com%2Fauth%2Fcallback&response_type=code">Authorize Notion</a>
  </body>
</html>
app.get("/auth/callback/:authCode/:token", (req, res) => {
  const authCode = req.params.authCode;
  const token = req.params.token;
  console.log(authCode);
  res.json({ status: "Success", code: authCode, token: token });
  axios.post('https://api.notion.com/v1/oauth/token', {
    grant_type: "authorization_code",
    code: authCode,
    redirect_uri: 'https://example-app.com/auth/callback'
  })
  .then(response => console.log(response))
  .catch(error => console.error(error));
});

It seems that the issue stems from the redirect URI not matching exactly between your authorization request and what you have configured in Notion’s app settings. In my experience, these kinds of errors often occur due to minor differences such as an extra parameter in your backend route or a slight mismatch in trailing slashes. Take a careful look at the expected route on your Notion settings and ensure that the callback URL in your code aligns perfectly without device-specific variations or additional segments.