Search code examples
google-apps-scriptweb-applicationsgoogle-sheetsgetgoogle-sheets-api

Cannot name get parameter 'pid' in google scripts get request


I want to pass a parameter to my google spreadsheet with a get request. The get parameter name is 'pid', which seems to make Google Sheets crash.

My example script just returns the get parameters to the client:

function doGet(e){
  try {
    return ContentService
          .createTextOutput(JSON.stringify({"result":"your parameters", "parameters": e.parameter}))
          .setMimeType(ContentService.MimeType.JSON);
  } catch(ee){
    return ContentService
          .createTextOutput(JSON.stringify({"result":"error", "error message": ee}))
          .setMimeType(ContentService.MimeType.JSON);
  }
}

The following request works:

https://script.google.com/macros/s/<sheet-id-here>/exec?a=1

returns:

{"result":"your parameters","parameters":{"a":"1"}}

But simply changing the get parameter name returns an error:

https://script.google.com/macros/s/<sheet-id-here>/exec?pid=1

returns:

We're sorry, a server error occurred. Please wait a bit and try again.

Any idea what's going on here and how to fix this? Is this a bug? Is there a way to handle this on the server side (can't really change my client code)?


Solution

  • It seems Google has changed reserved parameters. As written in the documentation,

    Warning: The following parameter names are reserved by the system and shouldn't be used in URL parameters or POST bodies:

    c
    sid

    Using these parameters may result in an HTTP 405 response with the error message "Sorry, the file you have requested does not exist." If possible, update your script to use different parameter names.

    It seems both c and sid parameters are valid now and pid parameter is reserved and throws

    Sorry, unable to open the file at this time.

    There doesn't seem to be anything that you can do server side.