0

I am trying to read a query through the Team Foundation Server 2015 Rest API. The following code works in Internet Explorer:

var tasksURI = tfs_url + collection + '/' + project + '/_apis/wit/wiql/' + queryId;


$.ajax({
    url: tasksURI,
    type: 'GET',
    contentType: "application/json",
    accepts: "application/json",
    cache: false,
    dataType: 'json'
  }).done(function (data) {
  var items = [];
  $.each(data.workItems, function (key, val) {
    items.push("<li> <a href='" + val.url + "'>" + val.id + "</a></li>");
  });

  $("<ul/>", {
    html: items.join("")
  }).appendTo("body");

});

In Chrome it yields the following error message:

Failed to load resource: the server responded with a status of 401 (Unauthorized)

I have seen this other question: TFS 2015 REST API Authentication

But I still get the same error if I follow the answer. Also I would prefer to prompt the user for the credentials (like in IE), and not store it.

What am I doing wrong?

Community
  • 1
  • 1
Gábor Angyal
  • 2,225
  • 17
  • 27

1 Answers1

0

I've tested your script, both IE and Chrome have 401 issue without Authorization header. But if you add the following into the script, both IE and Chrome are working:

 beforeSend: function (xhr) {
     xhr.setRequestHeader("Authorization", "Basic " + btoa("username" + ":" + "password"));
 },
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39