0
votes

I have created a Google Script and published it as a web app, very much like this post has.

However, I would like to call my extremely simple doGet method using Postman. The web app is published with anonymous access and execution permission as me.

I was expecting to be able to paste the URL into Postman, set the GET verb and hit Send - and to see the same result I see in the browser. I do not.

What am I doing wrong?

[UPDATE] Responding to comment by themaster

I have created a Google Apps Script called devices in my Google Drive. I've added this function:

function doDelete(e) {
  return HtmlService.createHtmlOutput('{"test":"yes"}');
}

Simple, I know, but should respond to a DELETE request with:

{
  "test": "yes"
}

I then hit Save, followed by Deploy > Publish as web app... with the following options:

  • Project version: new
  • Execute the app as: me
  • Who has access: Anyone, even anonymous

I hit Update and get a URL like this:

https://script.google.com/macros/s/ABcdefgHInmLDGiHmpGmXkXIxMjsh0s61sKZ9ov6OOSpkb--1quTtfM/exec

If the function is named doGet and I paste the URL into the browser, I see this JSON mentioned above.

If I leave the function named doDelete and I make a DELETE request from Postman, I get this:

Could not get any response There was an error connecting to https://script.google.com/macros/s/ABcdefgHInmLDGiHmpGmXkXIxMjsh0s61sKZ9ov6OOSpkb--1quTtfM/exec. Why this might have happened: The server couldn't send a response: Ensure that the backend is working properly Self-signed SSL certificates are being blocked: Fix this by turning off 'SSL certificate verification' in Settings > General Proxy configured incorrectly Ensure that proxy is configured correctly in Settings > Proxy Request timeout: Change request timeout in Settings > General

If I change the function to doGet, republish and call it with a GET request from Postman, I get the same result.

[EDIT] Clarification

If I make the Postman call using GET and have the doGet function setup to call an IFTTT webhook, the webhook does fire. I can also make it fire using the doPost and a POST request in Postman.

However, if I use doDelete with a DELETE request in Postman, the IFTTT webhook does not get called.

Regardless of the verb used in Postman I do not get a response - only the message quoted above.

[EDIT] Response to @sourabh-choraria question

My code currently is just this:

function doGet(e) {
  return HtmlService.createHtmlOutput('{"valid":"no"}');
}

Published with the process described above, I get this when calling with Postman:

Could not get any response

I am making that request as a GET without any headers.

1
What do you see instead? See minimal reproducible example - TheMaster
I'm assuming the issue is that I haven't got an authentication token in the header being sent by Postman, but I'm not sure how to acquire that when my browser doesn't seem to need it. Then again, I assume that's because I'm signed into my browser with the same account that the request is being run from/for. But then... the web app is set to allow anonymous access, so auth requirements would be moot, no? - Matt W
I have a suspicion that google apps scripts do not support HTTP verbs other than GET and POST with simple function names. - Matt W

1 Answers

2
votes

Currently, Google Apps Script's Web Apps only support the following HTTP methods, as per their requirements for web apps -

  • GET via doGet()
  • POST via doPost()

While not explicitly stated in the reference doc that PUT, DELETE, UPDATE etc. are unsupported, there is no way to execute those HTTP methods via Web Apps in Apps Script.