Home > Enterprise >  Parameters Are Empty for Simple doGet Apps Script Function. Why?
Parameters Are Empty for Simple doGet Apps Script Function. Why?

Time:04-10

Within Google Apps Scripts, I'm attempting to display the parameters being sent to my simple doGet function shown below:

function doGet(e) {
let response = e;
  return ContentService
.createTextOutput(JSON.stringify(response))
.setMimeType(ContentService.MimeType.JSON);
}

I attempt to throw in parameters to view them within Postman and no matter what I do, the output is empty.

[{
    "contentLength": -1,
    "parameter": {},
    "parameters": {},
    "queryString": "",
    "contextPath": ""
}][1]

My goal is this: How to get anything to show up in the parameters object?

Within Postman I am manually adding parameters and I replicated the same within my google browser. But it continues to be an empty object being returned.

What am I missing?

CodePudding user response:

The parameter and parameters properties are empty objects because the URL used to do the HTTP GET call doesn't include a query string

Instead of using

https://... /exec

use something like

https://... /exec?givenName=John&surname=Doe

The parameter property is {givenName:'John',surname:'Doe'}.

The parameters property is {givenName:['John'],surname:['Doe']}.

Resources

  • Related