Search code examples
google-apps-scripttestingweb-applications

Google Apps Script test mode parameters


How do you pass a parameter to a Google Apps Script while in test mode?

When I build an Apps Script and publish as a content service I can pass a parameter in the query string of the production version without a problem.

But during development if you follow these steps:

  1. Click on "Publish" from the menu bar
  2. Click on the "latest code" link found in the publish dialog in this sentence "Test web app for your latest code." near the top of the dialog.

The test URL for the Apps Script is different than the live URL and whenever I add to the query string of the test URL my parameter gets stripped out.


Solution

  • Found the problem.

    The "latest code" link has a URL that looks like this:

    https://script.google.com/macros/s/{key}/dev
    

    But when you click on it the response is redirected to a URL that looks like this:

    https://script.googleusercontent.com/macros/echo?user_content_key={very long key}&lib={other key}
    

    If you try to add a query parameter to the second URL the parameters will get stripped out and your script will not see them.

    So I had to copy the URL from the "latest code" link and paste it into the address bar and add my query string parameters and hit enter.

    https://script.google.com/macros/s/{key}/dev?param1=value1&param2=value2
    

    Then the script picked up the parameters just fine.

    But you have to copy the URL into the address bar every time. You cannot just add query string parameters to the redirected URL.