- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2021 08:07 AM
Hello All,
I want to check the request payload of the REST API that is sending out from ServiceNow instance. Is there any way to log the request body?
Please find the below REST API request:
var r = new sn_ws.RESTMessageV2('xxxxx', 'Create');
r.setStringParameter('u_caller', 'web_test');
r.setStringParameter('u_sub_category', 'Security gap');
r.setStringParameter('u_correlation_display', 'BRCMINFY');
r.setStringParameter('u_configuration_item', 'Cybersecurity Operations');
r.setStringParameter('u_category', 'Security');
r.setStringParameter('u_module', 'incident');
r.setStringParameter('u_purpose', purpose);
r.setStringParameter('u_contact_type', 'Integration');
r.setStringParameter('u_state', current.state);
r.setStringParameter('u_description', jsonEncode(current.description.replace(/"/g, "'") + ''));
r.setStringParameter('u_short_description', current.getValue('short_description'));
r.setStringParameter('u_impact', current.impact);
r.setStringParameter('u_urgency', current.urgency);
r.setStringParameter('u_correlation_id', current.sys_id);
r.setStringParameter('u_assignment_group', current.getDisplayValue('assignment_group'));
r.setStringParameter('u_additional_comments',jsonEncode(current.comments.getJournalEntry(1) + ''));
r.setStringParameter('u_work_notes', jsonEncode(current.work_notes.getJournalEntry(1) + ''));
r.setStringParameter('u_external_reference_number', current.getDisplayValue('number'));
if(current.state == 6){
r.setStringParameter('u_resolution_notes', current.getValue('close_notes'));
r.setStringParameter('u_resolution_code', current.getValue('close_code'));
}
var response = r.execute();
Thanks,
Deepak K
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2021 03:13 AM
Hi,
You can try to print the request body once you add the line which executed the API i.e. after
var response = r.execute();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2021 03:04 AM
Hi Ankur,
Thanks. I got your point.
For the time being, we are logging into logs table using getRequestBody() method from RESTMessageV2 API.
for example,
var sm = new sn_ws.RESTMessageV2("<REST_message_record>","get");
......
var body = sm.getRequestBody();
But I'm getting the logs as below:
"u_state":"${u_state}",
"u_assignment_group":"${u_assignment_group}",
"u_impact":"${u_impact}",
"u_urgency":"${u_urgency}",
"u_configuration_item":"${u_configuration_item}",
"u_category":"${u_category}",
"u_sub_category":"${u_sub_category}",
"u_business_service":"${u_business_service}",
"u_correlation_id":"${u_correlation_id}",
"u_correlation_display":"${u_correlation_display}",
"u_short_description":"${u_short_description}",
"u_description":"${u_description}",
"u_company":"${u_company}",
It is displaying the variables, not actual values.
Could you please help me how can we store that logs with actual values.
Thanks,
Deepak K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2021 03:13 AM
Hi,
You can try to print the request body once you add the line which executed the API i.e. after
var response = r.execute();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2021 04:55 AM
Hi Ankur,
Thanks, it's working.
Thanks,
Deepak K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2021 05:30 AM
Glad to know.
Please mark response helpful as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader