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;
}