Is it possible to trigger a Google Script function from retool?

I'm building a query and editing system for a google spreadsheet used as a database. As I have several functions already written in the Google API (Google script) that I trigger in the spreadsheet through a button, I would like to know if I can trigger this same function from the environment of a rettol application. Thanks

Hi @PepeVergara :wave:

It looks like Google Apps Script has a REST API. I think you might create a resource in Retool with an associated query that hits one of those endpoints to run your script. Let me know if that helps!

Thanks for the answer. That's right! what I did was publish the AppScript code as a web application and call it via http doget. that's it! Thank you!

I've done as was suggested here and it does work but does anyone know if it's possible to add some authentication. I've only managed to get it to work where the appscript.json is set to use access as ANYONE_ANONYMOUS, ideally I would like to use DOMAIN.

{
...
"runtimeVersion": "V8",
"webapp": {
"executeAs": "USER_DEPLOYING",
"access": "ANYONE_ANONYMOUS"
}
}

So for the absolute LIFE of me, I could not get this method to work. My Apps Scripts had too many scopes that required authentication and they weren't talking to each other appropriately.

So on the hunt for a different solution, I found one after several hours that may hopefully save the next sorry chap trying to do the same a couple hours.

  1. In your Apps Script, click Deploy > New deployment > API Executable.

  2. Now go to Deploy > Manage Deployments, make sure your most recent deployment is selected > scroll to the URL for API Executable > Copy.

  3. Go to your Resources Page and create a new REST API resource. Here is where you can establish your OAUTH2 flow with Google if you scroll to the bottom.
    3a. The Authorization URL and Access Token URL input boxes with the gray text still need to be typed in manually exactly how the placeholder text is shown

  4. The last URL we copied we'll paste into base URL. Follow these steps here..

  5. Follow this guide next.

  6. Now you should be able to create your queries using this new resource simply by adding function : <your apps script function name> to the body of the POST request.

This doc has the rest of the info you'll need.

Cheers,
Shaun

2 Likes

I can not thank you enough for this shaun... Should have looked for your post sooner. :wink: