How to log Outbound Rest API call request body?

Deepak K
Mega Guru

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

1 ACCEPTED SOLUTION

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Geoff_T
Mega Sage

Hi,

One way, if the REST call is being made via MidServer is to check the ECC Queue logs. You can check the payload and params passed.

You can also review Outbound HTTP Requests logs:

https://docs.servicenow.com/bundle/quebec-application-development/page/integrate/outbound-web-services/concept/outbound-request-logging.html

Geoff

Thanks Geoff,

 

Unfortunately, we are not using any mid server for this integration.

 

In Outbound HTTP Request logs, we have a limitation on number of characters when logging request body. It will display up to 1000 characters only.

Is there any chance can we extend the character length beyond 1000 characters.

 

Thanks,

Deepak K

Unfortunately the max limit is 1000 as set by the glide.outbound_http.content.max_limit property:

https://docs.servicenow.com/bundle/quebec-application-development/page/integrate/outbound-web-services/reference/outbound-logging-properties.html

 

Maybe some other alternative can be suggested by the community members.

Geoff

Ankur Bawiskar
Tera Patron
Tera Patron

@Deepak K 

So you better do this to overcome

1) create custom table with some fields like

a) Request body - length 4000

2) then create record into this table whenever you send the API request body so that you can view the JSON request body what was sent

Note: Using custom table will have cost implication based on your Subscription

Also ensure you clean up this table on regular interval or else this table will get bulku

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader