I am attempting to use UrlFetchApp
to access an external (Enjin) API and grab a JSON blob of info. Running the function by itself (basically a get function) provides the correct HTTP response. However, when calling the function from an onEdit()
trigger event, the Logger doesn't log any response?
Is there a difference when making external API requests from a trigger?
Here is the function itself:
function getUserID(name) {
var url = "URLHERE";
// Make a POST request with a JSON payload.
var data = {
'jsonrpc':'2.0',
'id': '12345',
'params':{
'api_key': '123'
},
'method': 'UserAdmin.get'
};
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(data)
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
return 1;
}
Already explained and suggested workAround can be found here:
UrlFetchApp.fetch() simply does not work in onEdit trigger
In short, simple trigger onEdit cannot be used to call UrlFetch. Instead, use installable triggers.
Hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With