2

I've done a new database with a user interface (with Javascript code) and Iam trying to connect the UI with TFS API to get some informations and save it in my Databas but i have challenge in establishing this connectioin with Javascript can anyone help me please??

Community
  • 1
  • 1
yahya.müll
  • 31
  • 1
  • 3

1 Answers1

0

If you want to do this via a javascript client, you could use the invoke as follows:

var self = this;
        self.tasksURI = 'https://<SERVER>/tfs/<COLLECTION>/<PROJECT>/_apis/build/builds?api-version=2.0';
        self.username = "<USERNAME>"; //basic username so no domain here.
        self.password = "<PASSWORD>";

        self.ajax = function (uri, method, data) {
            var request = {
                url: uri,
                type: method,
                contentType: "application/json",
                accepts: "application/json",
                cache: false,
                dataType: 'json',
                data: JSON.stringify(data),
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("Authorization", "Basic " + btoa(self.username + ":" + self.password));
                },
                error: function (jqXHR) {
                    console.log("ajax error " + jqXHR.status);
                }
            };
            return $.ajax(request);
        }

        self.ajax(self.tasksURI, 'GET').done(function (data) {

            alert(data);

        });

More details please refer this similar question in SO: TFS 2015 REST API Authentication

Community
  • 1
  • 1
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • if they use Windows-Authentication how can make the connection, i thought to use (PERSONAL ACCESS TOKEN) but in TFS-2015 there is no (PERSONAL ACCESS TOKEN). what do u think ?? thank u anyway – yahya.müll May 10 '17 at 08:13