Webhook problems with Google Apps Script web apps

1249
3
02-08-2019 03:28 PM
Highlighted
New Contributor III

I'm attempting to write develop a web app using Google Apps Script to handle Survey123 submission using webhooks.  I'm wondering if anyone has been able to successfully implement this yet.  My web app is not receiving the webhook posts.  It appears that everything is being blocked by a CORS issue.  In the Chrome DevTools console, I'm seeing this message:

Access to XMLHttpRequest at 'https://script.google.com/a..../exec' from origin 'https://survey123.arcgis.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Is there any possible fix or workaround for this, or is it an issue that ESRI and Google need to address between themselves? 

My organization (which is fairly large) uses Google G Suite to manage email, spreadsheets, and documents.  I want to deploy a Google Apps Script, as a web app, to handle the POST from the Survey123 webhook. Then, have the script email various people in my organization to let them know that a new survey form submission has been posted.

Any suggestions would be welcome.

webhooks  webhook‌ survey123 form‌ survey123 support‌ google ‌ #google apps script #webapp

Reply
0 Kudos
3 Replies
Highlighted
New Contributor III

Hi Justin Johnson‌,

Which webhook provider are you using (Ex. Integromat, Microsoft Flow) and could you provide a little more information about how you are configuring the webhook? Thanks!

Best,

Morgan

Reply
0 Kudos
Highlighted
New Contributor III

Thanks, Morgan

I'm hoping to handle the webhook using a Google Apps Script published as a web app.  It's basically a script that, when published, can respond to HTTP POST requests.  There is a brief description of the process here: 

https://developers.google.com/apps-script/guides/web 

We use Google G Suite internally, for all of our email and calendar coordination. I would like to have the Survey 123 webhook send a POST request with the event data to the Payload URL, which is the URL of the published web app on our application's G Suite.  As of now, the development URL for that script is:

https://script.google.com/a/utah.gov/macros/s/AKfycbwnT3nm474APPWufmyt2H1R960IeHDTSRcLFloQ8i4/dev 

The script at that URL should be able to handle a POST request from the webhook when a new record is posted in Survey123, extract the encoded data in the payload, then send email messages to a list of people in our organization with information from that new record. 

I'm not sure how to work around that CORS policy message, yet.  I'm not very experienced with the sort of web server configuration.  Ideally, I would like Survey123 to send the message to our published Google Web App directly, without going through a 3rd party handler such as Integromat or Microsoft Flow. 

Reply
0 Kudos
Highlighted
Esri Frequent Contributor

Hi Justin, you will need to enable CORS in your script. I would start by looking in Stack Overflow [google-apps-script] as recommended by Google.

After a quick search, this could be a potential solution:

You should specify Access-Control-Allow-Origin on Google Cloud side:

Cloud Storage allows you to set CORS configuration at the bucket level only. You can set the CORS configuration for a bucket using the gsutil command-line tool, the XML API, or the JSON API. For more information about setting CORS configuration on a bucket, see Configuring Cross-Origin Resource Sharing (CORS). For more information about CORS configuration elements, see Set Bucket CORS.

You can use either of the following XML API request URLs to obtain a response from Cloud Storage that contains the CORS headers:

storage.googleapis.com/[BUCKET_NAME]

[BUCKET_NAME].storage.googleapis.com