Scripted Rest API returns[object Object] how to parse ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2022 10:29 PM
Couldnt parse [object Object]
instance A:
rest api body is set
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://devxxxxx.service-now.com/api/757899/validatepredeploy');
request.setHttpMethod('POST');
var enc=current.u_enclave;
var user = 'admin';
var password = 'xxxxx';
var body ={};
body.enclave=enc;
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestBody(JSON.stringify(body));
var response = request.execute();
Instance B: scripted Rest API parsing to get value of enclave
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var requestBody = request.body.data;
gs.log('requestJSON enclave 1'+requestBody ,'sh01');
})(request, response);
Ouput:
requestJSON enclave 1[object Object]
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2022 11:14 PM
Hi Kiddy,
So there are two things:-
1) To retrieve the value of "Enclave" you will need to keep it in JSON format and do gs.log('requestJSON enclave 1 '+requestBody.enclave,'sh02');
As of now I do not see a value for enclave in the given screenshot.
2) Once you use stringify you are converting the entire JSON to string so that will just act like string data where data retrieval is difficult.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2022 11:56 PM
Thanks i fixed it using below code i think this was givinf me issue
var body ={};
body.enclave=enc;
to
var body ={};
body.enclave=enc+'';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 01:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 09:53 AM
Great 🙂
Please mark my answer correct if that really helped 🙂
Thanks,
Anirudha