Gmail API Watch Request Not Filtering Label IDs

Viewed 453

Issue

Trying to get the Gmail API to send only new messages to Cloud Pub/Sub by using the Gmail APIs Watch function but when setting the labelIds in order to filter to just INBOX, i am still notified of all changes, files sent, drafts etc.

I've looked online and can see that there are people that are experiencing this issue and there is even a bug out for it https://issuetracker.google.com/issues/36759803.

But i find it kind of odd that the entire feature of filtering just doesn't work and its been an issue for 5 years according to the bug report. Makes me think its just me that is doing something wrong. Would be cool to hear from anyone that has got this to work.

Where im at

I'm using the Gmail API, trying to get my Gmail account to publish messages to Cloud Pub/Sub. I've managed to do this however im trying to filter what i get notifications for to just new messages. This is where i have a problem.

According to this Gmail API documentation, it appears all i have to call is the code below and that should be that. I will add however, that im calling the Kotlin equivalent, but i don't think this should matter.

request = {
  'labelIds': ['INBOX'],
  'topicName': 'projects/myproject/topics/mytopic'
}
gmail.users().watch(userId='me', body=request).execute()

What im calling:

val request = WatchRequest().apply {
    labelIds = listOf("INBOX")
    topicName = "projects/myproject/topics/mytopic"
}

gmail.users().watch("me", request).execute()

Other things ive tried

I have tried adding labelFilterAction = Include and other variations but they all seem to be ignored.

2 Answers

After trying the ideas listed by ziganotschka, I'm more confident that the issue is not related to specific client libraries.

I managed to speak to someone at Google who in turn contacted the G-mail API team. They said they were aware that this is an issue, that it has been an issue since 2015 and was most likely caused by a change they made back then.

A ticket is still open, but doesn't look like it will be fixed.

Perform the following trouble-shooting actions

  1. Provide a request body including labelIds, labelFilterAction AND topicName as specified here
  2. Try the label "UNREAD" instead of "INBOX"
  3. To discart Kotlin implementation related issues, test your request in a programming language that allows you to pass the request as a JSON body in exactly the same way as specified in the documentation.
Related