Oletros
Oletros

Reputation: 127

Bad request using UrlFetchApp.fetch method

I'm trying to get the list of tags from Pinboard.in using it's api but I get an error when the fetch method is executed.

The code is:

function getTags(user, password) {
  var url ="https://"+user+":"+password+"@api.pinboard.in/v1/tags/get"
  var response=httpGet(url);
  return response;
}
function httpGet(theUrl)
    {
      var options = { "contentType" : "application/xml; charset=utf-8"} ;
      var response = UrlFetchApp.fetch(theUrl,options);
      return response.getContentText();
    }

What I'm doing wrong?

Upvotes: 1

Views: 2327

Answers (1)

Eric Koleda
Eric Koleda

Reputation: 12673

Unfortunately the user:password@ prefix notation is not supported by UrlFetchApp. Instead you'll have to construct the Authorization header manually, using code like:

var response = UrlFetchApp.fetch('https://api.pinboard.in/v1/tags/get', {
  headers: {
    Authorization: 'Basic ' + Utilities.base64Encode(user + ':' + password)
  }
});

Upvotes: 4

Related Questions