Blank response from UrlFetchApp in Google App Script

笑着哭i 提交于 2021-01-28 07:01:54

问题


I'm trying to test the endpoints of an API and all the responses return blank with no errors.

I've tested using curl and the response actually has data in:

curl --request GET https://myapiurl.com/endpoint --header "authorization: bearer TOKEN"

Here's the segment of GAS code. The token property is set when I run a POST call to retrieve it, it expires after a while:

  var url = 'https://myapiurl.com/endpoint';
  var token = 'bearer TOKEN';
  var headers = {
    'authorization': token
  };
  var options = {
    'headers' : headers
  };
  var response = UrlFetchApp.fetch(url,options);
  var data = JSON.parse(response.getContentText());

The response should be a JSON object with a full list of keys/values. The response from curl is exactly what it should be, but the GAS version is blank, no errors.

I am completely at a loss, any help would be much appreciated!

来源:https://stackoverflow.com/questions/57631757/blank-response-from-urlfetchapp-in-google-app-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!