# Configuring Pub/Sub for Gmail API Webhooks

This guide explains how to set up Google Cloud Pub/Sub (Pub/Sub) for Aurinko to receive push notifications from the Gmail API. Using Pub/Sub eliminates the need for constant polling of your Gmail inbox for updates, improving efficiency.

To get started, head over to [https://console.developers.google.com](https://console.developers.google.com/). You will be prompted to log in with a Google account if you're not already logged in with one.

Select your project, or create a new one. Refer to [this article](https://docs.aurinko.io/authentication/google-oauth-setup) if creating a new project, the Gmail API needs to be enabled!

### Pub/Sub topic setup

***

1. Head over to the Pub/Sub page

<div data-full-width="true"><figure><img src="https://3933352743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0ua36KLVlbUN5bA2bgiq%2Fuploads%2FwcU2b5fTLCD9BtGWWtjx%2Fimage.png?alt=media&#x26;token=83d84eb5-c76d-45bc-b9a8-d7ce70ba82e3" alt=""><figcaption></figcaption></figure></div>

2. Create a new topic. The default options will do:

<div data-full-width="true"><figure><img src="https://3933352743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0ua36KLVlbUN5bA2bgiq%2Fuploads%2Fct65Wl24NeDnNKYxxFHR%2Fimage.png?alt=media&#x26;token=825618ba-781a-49c8-89dc-1ad195118833" alt=""><figcaption></figcaption></figure></div>

3. Copy the topic name and enter it in your Aurinko app settings:

<div data-full-width="true"><figure><img src="https://3933352743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0ua36KLVlbUN5bA2bgiq%2Fuploads%2FSaZE4fwu4xi4VPXmQrCH%2Fimage.png?alt=media&#x26;token=b6782dda-dfb9-4c87-87bf-11228ee76b03" alt=""><figcaption></figcaption></figure></div>

4. Back in the Google Developer console, edit the default subscription that was created for your new topic. Make it a Push subscription with the following 'Endpoint URL': <mark style="color:red;">`https://api.aurinko.io/push/google/email/{clientId}`</mark>

<div data-full-width="true"><figure><img src="https://3933352743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0ua36KLVlbUN5bA2bgiq%2Fuploads%2FoK02gAtIFpf8WCfXhh4o%2Fimage.png?alt=media&#x26;token=d1e8ebf3-3d61-4901-8980-559d40cb7f1a" alt=""><figcaption></figcaption></figure></div>

Also, change the retry policy and save:

<div data-full-width="true"><figure><img src="https://3933352743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0ua36KLVlbUN5bA2bgiq%2Fuploads%2FIsQcwDuyQEWzC12eEoJH%2Fimage.png?alt=media&#x26;token=eeba8ed2-8231-4882-81ed-93d5d7f7e863" alt=""><figcaption></figcaption></figure></div>

5. Go back to the **'Topics'** menu and click **'View permissions'** for your new topic.

<div data-full-width="true"><figure><img src="https://3933352743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0ua36KLVlbUN5bA2bgiq%2Fuploads%2FE54xLNGCqYiBdR5OzKf2%2Fimage.png?alt=media&#x26;token=a750be82-f845-4b41-b698-441dc42b655d" alt=""><figcaption></figcaption></figure></div>

6. Now, let's grant Gmail privileges to publish notifications to your topic.

Click '**ADD PRINCIPLE'** and grant publish privileges to <mark style="color:red;">`gmail-api-push@system.gserviceaccount.com`</mark>:

<div data-full-width="true"><figure><img src="https://3933352743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0ua36KLVlbUN5bA2bgiq%2Fuploads%2FXSPtjZdFh3yugfqwvB67%2Fimage.png?alt=media&#x26;token=a127f506-b0de-479d-ac82-57760494573a" alt=""><figcaption></figcaption></figure></div>

**You are done!**
