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.

User Not Authenticated error when accessing the Rest table api.

guptashalini041
Kilo Contributor

Hi,

I am getting below error when trying to access the Servicenow rest api.

401{"error":{"message":"User Not Authenticated","detail":"Required to provide Auth information"},"status":"failure"}

Below is the java script code by which I want to access the rest api.

<script type = "text/javascript">

function CallServicenow()
{

var requestBody = "";

var client=new XMLHttpRequest();
client.open("get","https://*****.service-now.com/api/now/table/incident?sysparm_limit=1");


client.setRequestHeader('Accept','application/json');
client.setRequestHeader('Content-Type','application/json');

//Eg. UserName="admin", Password="admin" for this code sample.
client.setRequestHeader('Authorization', 'Basic '+btoa('admin'+':'+'admin'));

client.onreadystatechange = function() {
 if(this.readyState == this.DONE) {
  document.getElementById("response").innerHTML=this.status + this.response;
 }
};
client.send(requestBody);

}
</script>

 

Below are the role assigned to this user.
admin
itil
personalize_dictionary
rest_api_explorer
rest_service
security_admin
snc_internal
web_service_admin

 

If I directly access the below url then it works. but not working when trying to access using script.

https://*****.service-now.com/api/now/table/incident?sysparm_limit=1

3 REPLIES 3

Harsh Vardhan
Giga Patron

adding one thread here.. can you try this way.. just to validate if it's related to authentication issue or something else.

https://community.servicenow.com/community?id=community_question&sys_id=c12d43a9db9cdbc01dcaf3231f96...

Hi Harshvardhan,

 

I tested it with Servicenow Script and it's working fine. But Java script and python script is not working and sending the below error :

401{"error":{"message":"User Not Authenticated","detail":"Required to provide Auth information"},"status":"failure"}

Any suggestion please..

thanks

 

adding one article here.kindly refer that.

also have you defined the "CORS" rule? if not then kindly define and try again.

 

https://hi.service-now.com/kb_view.do?sysparm_article=KB0565021

 

CORS Rule

Thread related to CORS Rule