Trouble Syncing Gmail with Nylas API – Need Help with OAuth Setup!

Hi everyone,

I am working on integrating Gmail using the Nylas API for an app that automates email follow-ups. I have followed the docs on setting up OAuth but keep hitting a redirect_uri_mismatch error when trying to authorize accounts.

Here’s what I have done so far:

  • Created a Google Cloud project and set up OAuth 2.0 credentials

  • Using the Nylas SDK for Node.js

Still, the OAuth flow fails right after the user grants permission. I suspect I might be missing a step in Google’s consent screen config or redirect handling.

Has anyone faced a similar issue recently: ?? Any tips or sample working configs would be really appreciated. I am trying to ensure a seamless Gmail sync experience. I have also gone through this resource https://developer.nylas.com/docs/dev-guide/provider-guides/google/machine-learning-course-in-mumbai
but couldn’t get enough help.

Thanks in advance !!

With Regards,
Marcelo

The redirect_uri_mismatch error you’re encountering is a common issue when the redirect URI in your Google Cloud project doesn’t match what Nylas expects (https://support.nylas.com/hc/en-us/articles/4423732212241-Why-is-my-Google-Cloud-Application-having-an-issue-with-Nylas-and-the-redirect-URI).

Required Redirect URI Configuration

For your Google Cloud application to work with Nylas, you need to add the correct Authorized Redirect URI in your Google Cloud project. The specific URI depends on your data residency:

Steps to Fix the Issue

  1. Update Google Cloud Console: Go to your Google Cloud Platform dashboard, select Credentials, then update the Authorized redirect URIs to include the correct Nylas callback URL above (Create a Google auth app | Docs).
  2. Verify Your Node.js Configuration: Make sure your Nylas SDK setup matches this pattern (Using the Node.js SDK | Docs):

javascript

import Nylas from "nylas";
const nylas = new Nylas({   apiKey: "<NYLAS_API_KEY>",   apiUri: "<NYLAS_API_URI>"});

(Using the Node.js SDK | Docs)

  1. Check Your Auth URL Generation: Your authentication URL should be generated like this (Using the Node.js SDK | Docs):

javascript

app.get("/nylas/auth", (req, res) => {   const authUrl = nylas.auth.urlForOAuth2({     clientId: "<NYLAS_CLIENT_ID>",     redirectUri: "<YOUR_APP_CALLBACK_URI>",     provider: 'google'   });    res.redirect(authUrl);});

(Using the Node.js SDK | Docs)

All the best!