Access servicenow data from (3rd party) web application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 03:21 AM
Hi everybody,
I have a requirement to get the servicenow data to view in a web application.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 03:34 AM
Hi Guru,
Please find below the documentation link to using authentication with the REST API:
Kind regards
Tracey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 03:58 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 04:28 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 04:04 AM
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!