3

I'm using a google script to connect to an external API with the 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 is this returning the following error?

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

1 Answer 1

1

Try removing the contentType from parameters and give it a shot.

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

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

will trigger the browser to send a preflight OPTIONS request to the server.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I tried removing the contentType and I got the same error.
Are you sending the right set of parameters? You're supposed to send a secure_auth_key in the parameters, failing which would lead to 401 error. help.ecwid.com/customer/portal/articles/…
I'm sending the key in the header parameter. 'yyy' in my code above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.