Unexpected Error On Urlfetchapp.fetch In Google Apps Script
I'm trying to access the Pingdom API in Google Apps script following that example: https://developers.google.com/apps-script/external_apis query = 'credits'; var username = 'foo';
Solution 1:
It appears that including login information in the URL is causing an error in UrlFetchApp. Please file a bug in our Issue Tracker. In the mean time, put the login information in the Authorization header and it should work correctly.
var response = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'Basic ' + Utilities.base64Encode(username + ':' + password)
}
});
Solution 2:
I encountered similar problems trying to access the Gitlab API in Google Apps Script. As mentioned in the accepted answer, including login information in the URL causes an error. The Basic Authorization method in the accepted answer did not work for me in Google Apps Script either. Modifying the authorization header to the 'Bearer' type did the trick.
var url = "https://gitlab.com/api/v4/projects/" + projectId;
var options = {
'headers' : {Authorization: 'Bearer ' + token}
};
var response = UrlFetchApp.fetch(url, options);
Post a Comment for "Unexpected Error On Urlfetchapp.fetch In Google Apps Script"