Read Gmail POST Notification using Standard Google Cloud Platform (GCP) Script

47 views
Skip to first unread message

Josh Manhiem

unread,
Dec 18, 2019, 9:12:58 AM12/18/19
to Google Apps Script Community

I am trying to create a subscribing webapp using Google Scripts App to receive and decode POST notifications from Gmail API whenever a new email is received. The new changes in the Google Cloud Platform (GCP) is making it very hard to work. All the documentation/videos I have found about this are obsolete.

I created a script with a doPost() function directly from Google Drive (not linked to Google Docs, Sheets or Forms) and deployed it as a webapp with a provided link. I had to link the script with a standard GCP project as the default GCP projects which are automatically created for any Google Scripts App are not accessible anymore. The next step was to go to PubSub API in GCP, created a topic. When I try to create a subscription to allow the webapp to receive the POST messages from Gmail API, and set its delivery type to PUSH, an Endpoint URL is required. When I use the webapp link, I get the error:


The supplied URL is not registered in the subscription's parent project. Please see documentation on domain ownership validation.


I went throug the domain ownership validation and tried all possible solutions I found online without success. Without the PUSH subscription, I am unable to receive the notification, decode its body, get the email id then retrieve and decode the email body. Any help is highly appreciated.

Dimu Designs

unread,
Dec 18, 2019, 4:12:18 PM12/18/19
to Google Apps Script Community
Up until a few months ago we had the option of registering GAS Web Apps under the Chrome Web Store and doing so would automatically verify Web App urls. That function is now removed and, as far as I know, Google has yet to supply another method to verify Web App urls.

Nowadays, when I need to use Google API push notifications (for Gmail, Drive, Admin Directory or Calendar) I leverage Google Cloud Functions instead of a GAS Web App. Cloud functions are far more versatile and you can deploy logic as a Node.js or Python module. Moreover, you can easily import 3rd party libraries from package managers such as NPM. You'll need to enable billing on your cloud project to access them; you'll get 2 million free invocations per month after which you'll have to pay a fee for usage exceeding the free quota.

Josh Manhiem

unread,
Dec 24, 2019, 9:25:45 AM12/24/19
to Google Apps Script Community
Dimu,

Thank you so much for your reply. I would like to do the same and leverage Google Cloud Functions for my application. May you share the steps to do that please?

Thanks in advance.

Josh
Reply all
Reply to author
Forward
0 new messages