Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

XMLHttpRequest with the current user credentials

Andrew Pishchul
Giga Expert

Looking for options how to execute XMLHttpRequest with the current (logged in) user's credentials.

Very simple code (UI script), same domain/origin, but it doesn't work - every time it asks for credentials:

var data = JSON.stringify({

  "short_description": "Hello"

});

var xhr = new XMLHttpRequest();

xhr.withCredentials = true;

xhr.open("POST", "https://XXXX.service-now.com/api/now/table/incident");

xhr.setRequestHeader("content-type", "application/json");

xhr.setRequestHeader("Access-Control-Allow-Credentials","true");

xhr.send(data);

Any ideas? josh.nerius?

1 ACCEPTED SOLUTION

Andrew Pishchul
Giga Expert

Found the solution: X-UserToken


View solution in original post

2 REPLIES 2

Andrew Pishchul
Giga Expert

Found the solution: X-UserToken


krishnaj22
Tera Contributor

use the following in ui page

var userToken = document.getElementById('sysparm_ck').value;
oReq.setRequestHeader("X-UserToken", userToken);