4

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;
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
Pejman Poh
  • 493
  • 2
  • 8
  • 20

1 Answers1

6

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

Community
  • 1
  • 1
Jack Brown
  • 5,802
  • 2
  • 12
  • 27