Google Pub/Sub for Message Sync
If you want to sync data between Gmail and Nylas even faster, you can use Google Pub/Sub for real-time syncing of Gmail messages. This guide will take you through the set up process.
Prerequisites
- An existing Google app connected to your Nylas application.
Step 1: Create a Service Account
-
Go to the project you created for use with Nylas.
-
In the search bar, type Service Accounts.
-
On the screen that opens, click CREATE SERVICE ACCOUNT.
-
Give the account the name
nylas-gmail-realtime
.The name,
nylas-gmail-realtime
, is required for the integration to work. -
Leave Grant this service account access to project (optional) and Grant users access to this service account (optional) blank.
-
Click Done.
Step 2: Create Pub/Sub Topic
Your Pub/Sub Topic MUST be set up in the same Google app you use to authenticate accounts with Nylas.
- In the search bar look for pub sub and select Pub/Sub.
- Click CREATE TOPIC.
- Enter the topic ID
nylas-gmail-realtime
, and leave the defaults checked. The topic ID listed is required for the integration to work. - On the next page, click SHOW INFO PANEL, if it's not already open.
- In the panel click ADD PRINCIPAL.
- Add the principal
gmail-api-push@system.gserviceaccount.com
. - Set the role to Pub/Sub Publisher.
- On save you should be directed to the Topics page.
- On the Topics page find the Subscriptions section. Click
nylas-gmail-realtime-sub
. - Click the subscription, then click edit.
- Change the following:
- Delivery type: Push
- Endpoint URL:
- for US use
https://gmailrealtime.us.nylas.com
- for EU use
https://gmailrealtime.eu.nylas.com
- for US use
- Select Enable Authentication and choose the service account you made in Create a Service Account.
If you are setting up multiple regions in a single GCP application, create a subscription for each region
- When prompted, grant the
roles/iam.serviceAccountTokenCreator
to your service account.If you miss the prompt or it does not appear, follow these steps to add the role to your service account:
- Go to IAM & Admin > Service Accounts
- Copy the full service account email for the service account you created in Step 1 (should start with
nylas-gmail-realtime
). - Select the service account (should be called
nylas-gmail-realtime
) - Go to the Permissions tab.
- Make sure you are on the Principals tab at the bottom.
- If the service account
nylas-gmail-realtime-email
is not listed under principals, click Grant Access and paste the email into the New Principles field.- If it is listed, click the edit icon next to that principal.
- On the pop-up, click ADD ANOTHER ROLE.
- Search for
service account token creator
- Select the role.
- Hit SAVE.
- Leave the other fields as default and click Update.
- After saving, it will take you back to the Subscription page. Copy the Topic Name for the next step.
The topic name must be nylas-gmail-realtime
. The principal must use the email gmail-api-push@system.gserviceaccount.com
for Google Pub/Sub to work.
Step 3: Add the Topic Name to Your Dashboard
Before adding the Topic name, we need to enable Google Pub/Sub for your application.
- Go to App Settings.
- Click on the Authentication tab and go to Google Auth. There is a input called GCP Topic Name. Input the topic created in Create a Pub/Sub Topic, for example,
projects/nylas-test/topics/nylas-gmail-realtime
. - Repeat steps one and two for every Nylas app you would like real-time Gmail message sync for.
- You can use the same Pub/Sub topic for all your Nylas apps.