Access servicenow data from (3rd party) web application

guru_elearn
Kilo Expert

Hi everybody,

I have a requirement to get the servicenow data to view in a web application.

find_real_file.png

I have tried with REST API Explorer, and get the HTTP Method/ URI as above, url as. I am a admin user.

if I directly use this URI in the browser, again the browser prompt me to enter user name & password. It does not accept my username/pwd and it prompt again.

How do I access the servicenow data using REST API or other method?

could you please help me in this?

thanks

guru

6 REPLIES 6

traceymaycock
ServiceNow Employee
ServiceNow Employee

Hi Guru,



Please find below the documentation link to using authentication with the REST API:



Outbound REST authentication



Kind regards



Tracey


tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Guru,


Once you have successfully validated that, say, a get against the incident table succeeds, you can obtain a code sample in various languages that you can use to send the request. Links for code samples appear at the bottom of the form. Click a link to view or copy the code sample for that language. The code samples change based on data you enter on the form. Code samples are available in these languages:


  • ServiceNow Script
  • cURL
  • Python
  • Ruby
  • JavaScript
  • Perl
  • Powershell


For example   java script



var requestBody = "";



var client=new XMLHttpRequest();


client.open("get","https://instance_name.service-now.com/api/now/table/incident/adee662413890300125ad8228144b0f6");



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);



REST API explorer elements


Screen Shot 2017-09-25 at 12.49.46 PM.png


Hi Anthony Barratt,



Thanks a lot for your response. I have tried the same what you have suggested. No data in the "Response text". It simply shows "error" text.


I have given my user name / password in this script.



thanks


guru


Dave Smith1
ServiceNow Employee
ServiceNow Employee

Guru A wrote:



if I directly use this URI in the browser, again the browser prompt me to enter user name & password. It does not accept my username/pwd and it prompt again.


This suggests you need to set up authentication for the API.



Given it's incident data and therefore somewhat commercially sensitive, that would make sense.   Did you create a user account to access the required data?



Also:



I have a requirement to get the servicenow data to view in a web application.


That's... pretty much the purpose of a ServiceNow platform.   Requirement fulfilled!