Orchestrator API remote calls : server responds with a 500 status

Hi,
I’m trying to make WebAPI calls as described here : UiPath WebAPI Authenticates User and receive the following output
{“message”:“An error has occurred.”,“errorCode”:0}
500 “”

when the code (below, at the bottom) is executed in a normal web application.

However, if I make the same API call from UiPath Studio using a HTTP Request Activity, it returns an authorization bearer token.

Whats wrong with this code? Why isn’t the server returning the authorization token.

An observation : GET requests return proper results but not POST when called from a non UiPath project. (not using UiPath Studio’s HTTP Request activity)

// Login

var data = new Object();
data.TenancyName = “XTenancyName”;
data.UsernameOrEmailAddress = “XUserName”;
data.Password = “XPassword1”;
var jsondata = JSON.stringify(data);
var xhr = new XMLHttpRequest();
//xhr.withCredentials = true;
xhr.addEventListener(“readystatechange”, function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
console.log(this.status, this.statusText);
}
});
xhr.open(“POST”, “https://www.xuipathorchestrator.com/api/account/authenticate”);
//xhr.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
xhr.send(jsondata);

@Chatur @aksh1yadav

We do face the similar challenge in our work where the API is invoked using the Non-UI Path application and we are in 2018.1 version on Cloud. Can you please let us know how to resolve the 500 error ? The error is not consistent and it occurs intermittently