Gmail API Watch() not working

3k views Asked by At

I am following Gmail API Push notifications guide given at https://developers.google.com/gmail/api/guides/push. However, when I try to create a new watch from API explorer, it gives following response:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalidArgument",
    "message": "Invalid topicName does not match projects/google.com:apisexplorerconsole/topics/*"
   }
  ],
  "code": 400,
  "message": "Invalid topicName does not match projects/google.com:apisexplorerconsole/topics/*"
 }

}

My request seems as follows:

POST https://www.googleapis.com/gmail/v1/users/myemailaddress/watch?key={YOUR_API_KEY}
{
 "labelIds": [
  "INBOX"
 ],
 "topicName": "projects/my-project-name/topics/my-topic-name"
}

Seems like faulty validation check at Google API end. Anyone else facing this problem?

1

There are 1 answers

2
Eric D On BEST ANSWER

You can't use APIs explorer to make that call, you need to make it directly (using your client, not APIs explorer) for it to be correctly verified as per the guide: https://developers.google.com/gmail/api/guides/push#gmail_watch

If that check were not done, you could in theory use APIs explorer to send notifications to any random other developer's Cloud Pub/Sub topic.