Unable to make a fetch request to an apps script function using Run JS Code

I am trying to make a fetch request to a google apps script using below Run JS Code resource. I deployed the google apps script as a web app and invoking from retool. The reason I would like to use fetch within retool is I would like to abort it using AbortController as soon as the request is submitted to Google server as this would be a long running back end process. When the JS code is triggered I am seeing at the Google side an error saying "Script function not found : doGet" where as I am calling doPost function specified as URL parameter and also as part of fetch call options ("method": "POST")
Not sure what query is being sent to Google server. Is it possible to have a trace of this as the normal debug is not showing any thing in this regard
Alternately if there are other ways to achieve the objective of executing such long running back end jobs in google server are available please suggest

Code snippets are below

const url = "https://script.google.com/macros/s/scriptID/exec?function=doPost";

function fetchDataWithTimeout(url,options, timeoutInMilliseconds) {
const controller = new AbortController();
const signal = controller.signal;
const timeout = setTimeout(() => controller.abort(), timeoutInMilliseconds);
console.log('inside try block, before fetch')
return fetch(url, {options, signal })
.then(response => {return response.json()} )
.then(result => {console.log(' result from api call', result);
return result;})
catch (error)
clearTimeout(timeout); // Clear timeout even on error
if (error.name === 'AbortError') {
console.log('Request aborted due to timeout',error.message, error.name);
} else
console.error('Error fetching data from google service:', error.message, error.name);
throw error; // Re-throw the error for further handling (o
//const response = await fetch(url);
clearTimeout(timeout); // Clear timeout if request finishes successfully


Hi @srichint Thanks for reaching out!

Currently, I am getting an 'AbortController' is not defined error with this code. We have a feature request to support abort queries, so I can let you know if we ship a fix for this!

What is your app use case? About how long is this action expected to take?

Thanks Tess for your reply. Good news is though I see this error in debug and inside the code I am able to run the application as expected. The use case is user would select some records in a table and then clicks on submit which would initiate a lengthy process in google cloud platform which interacts with Database, prepare some documents, email the doc. The duration is based on the number of records selected by the user and hence it is dynamic. Any way for me currently it works and I hope this would continue to do so (hope Retool does not do any thing which breaks this :slight_smile: )

1 Like