- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2015 08:23 PM
Hey guys,
I'm developing an application which interacts a lot with REST. In some case, the error will be occurred such as Authorization header is error and I want to get the response body for debugging. With previous version of RESTResponse, I can do log the response body but in V2, the body always is null if haveError() is true. Is there any work around for this?
Cheers,
Duc
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-16-2015 08:59 PM
Seems like SNC changed in getBody() method of RESTResponseV2. Now I can get the body even haveError() is true
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2015 08:41 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2015 08:52 PM
Hi Pradeep Sharma,
Thanks for your helping but I use Outbound REST API. So sometime REST API has error, it'll return a lot of content in response such as JSON. For troubleshooting, I need to get the response body. Is there any work around?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2015 10:05 PM
Hi Duc,
Could you supply some more details?
You are using outbound rest api described here?
Outbound REST Web Service - ServiceNow Wiki
With or without a MID Server?
Are you on Fuji or earlier?
Towards another instance? Or something else?
You mention version V2 what does that refer to?
Best Regards
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2015 02:45 AM
Hi Tony,
I'll explain more for you:
- I'm on FUJI version
- I use RESTMessageV2 and execute request with MID Server
- After I sent request to REST API endpoint, I got status code is 401. The REST API endpoint returns the JSON response when status code is 401. BUT response.getBody() is null.
FYI: The code is
// SAPI is name of REST API
var restMessage = new sn_ws.RESTMessageV2("SAPI", "get");
restMessage.setBasicAuth('myuser', 'mypassword');
restMessage.setMIDServer('MYMIDSERVER');
var response = restMessage.execute();
response.waitForResponse(120);
gs.debug('Response body: {0}', response.getBody());
FYI2: If response.hasError(), the response.getBody() always is null
