Rest API Response in browser is always in XML instead of JSON
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 03:22 PM
Am writing a simple scripted rest api to place order using cart API.The response in servicenow rest api explorer is in JSON,
but when i run in browser, it always shows up in xml, i have seen many others had this question and is unanswered.Amy pointers will help
Thanks,
Anirudh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 03:46 PM
The first thing I would look at is the request headers. Set it something similar to "Accept=application/json"
If one is not set, it may default to XML.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 04:26 PM
Hello Jarod,
I did try setting these in my script but didnt help
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 11:13 AM
I figured this out from docs.servicenow.com,
used var writer = response.getStreamWriter() and built the object and converted in the end using global.JSON.stringify(responseObj)
Thanks,
Anirudh