Trigger teamcity run using javascript

Read the following code:

function connectingToSP() {
(function () {
var cors_api_host = ‘cors-anywhere.herokuapp.com’;
var cors_api_url = ‘https://’ + cors_api_host + ‘/’;
var slice = [].slice;
var origin = window.location.protocol + ‘//’ + window.location.host;
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function () {
var args = slice.call(arguments);
var targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1]);
if (targetOrigin && targetOrigin[0].toLowerCase() !== origin &&
targetOrigin[1] !== cors_api_host) {
args[1] = cors_api_url + args[1];
}
return open.apply(this, args);
};
})();

var spURL = “https://yourteamcityhere/httpAuth/app/rest/builds”;

function getWWWAuthentication() {
var dfd = $.Deferred();

$.ajax({
url: spURL,
beforeSend: function(xhr) {
xhr.setRequestHeader(“Authorization”, “Basic ” + btoa(“username:password”));
},
type: ‘GET’,
dataType: ‘json’,
contentType: ‘application/json’,
processData: false,
success: function (data) {
alert(JSON.stringify(data));
dfd.resolve(data);
},
error: function(){
dfd.resolve(null);
}
});

return dfd.promise();
}

getWWWAuthentication()
.then();
}

connectingToSP();