Google App Script 401 connection error

I am using google script to connect to external API with code:

  var url='https://app.ecwid.com/api/v1/XXX/orders'

  var parameters = { method : 'get',
                    headers : {'Authorization': 'Bearer '+'yyy'}, 
                    contentType:'application/json',                   
                    muteHttpExceptions:true};

  var response = UrlFetchApp.fetch(url,parameters).getContentText();

  Logger.log(response);

      

But why does this return the following error?

HTTP ERROR 401
Problem accessing /api/v1/XXX/orders. Reason:
    Unauthorized

      

+3


source to share


1 answer


Try to remove ContentType from options and take a snapshot.

For cross-domain requests, setting the content type to something other than



  • application / x-www-form-urlencoded
  • multipart / form-data
  • Text / plain

will cause the browser to send an OPTIONS request to the server.

+1


source







All Articles