gmail-apigoogle-cloud-pubsub

Gmail api does not trig pub/sub webhook


I want to receive webhook requests when I get new emails, but it does not work. Here are the steps (Push Notifications)

I have already done:

  1. Created a Pub/Sub topic.
  2. Added gmail-api-push@system.gserviceaccount.com as a Pub/Sub publisher for the new topic. enter image description here
  3. Created a new subscription, set the delivery type to push, and configured my server's webhook endpoint.
  4. Tested that my webhook endpoint is accessible from the public network and confirmed it works with manual push messages. My server received requests from Pub/Sub.

The problem is that when I send an email to my mailbox, Gmail does not trigger Pub/Sub to send a webhook to my server.


Here is my server watch code (this code works fine for manual push but does not receive any requests when the email inbox changes):

async setWatch() {
    try {
      const topicName = "projects/projectName/topics/topicName"
      const gmail = google.gmail({ version: "v1", auth: this.oAuth2Client })
      await gmail.users.watch({
        userId: "me",
        requestBody: {
          topicName: topicName,
          labelIds: ["INBOX"],
        },
      })
    } catch (error) {
      console.log(error)
      return null
    }
  }

What am I forgetting or missing? please help. thanks.


Solution

  • I tried every setting I could think of that might relate to preventing the Gmail API from triggering Pub/Sub, and I finally found the solution. The problem was that my current project status was set to production mode. I switched it back to development mode and then switched it back to production mode again. The problem was solved.