Outbound REST Error

Robert Beeman
Kilo Sage

I'm trying to set up a scripted REST integration (we're on Fuji) with an internal application through our mid server. I'm trying to set up error handling, but I'm not able to figure out how to read the response. This is a screen shot from Advanced Rest Client Chrome app. This shows me the status code, error message, but it also returns the response with a JSON object that has important information. I can't seem to retrieve it from the RESTResponseV2 object.

find_real_file.png

This is what I get in my response from ServiceNow:

error: string = Method failed: (/common/internal/crm/provisioning/employees/create) with code: 400

response: null = null

status: number = 400

If it returns a 200 then that response does show the same response that is in the Chrome app (isntead of null = null).

Any ideas? TIA!

1 ACCEPTED SOLUTION

Hi Robert,



Could this be relevant?


ServiceNow KB: PRB664609: RESTResponseV2.getErrorMessage() does not return message from the outbound...



It does seem to explain why the info about the failure is available in the Chrome Rest Client but not via getErrorMessage().



Best Regards



Tony


View solution in original post

7 REPLIES 7

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Robert,



Code 400 can be for example if you provide wrong headers:



REST API - ServiceNow Wiki



Regards,


Sergiu


venkata_koya
ServiceNow Employee
ServiceNow Employee

Can you try to see if this API works in case of error to get response body


RESTResponseV2 - getErrorMessage()


Hi Venkata,



Yes, the getErrorMessage() method is what is returning "Method failed: (/common/internal/crm/provisioning/employees/create) with code: 400 ", which is not useful. I want what should be in getBody(), but that is returning null = null.


Hi Robert,



Could this be relevant?


ServiceNow KB: PRB664609: RESTResponseV2.getErrorMessage() does not return message from the outbound...



It does seem to explain why the info about the failure is available in the Chrome Rest Client but not via getErrorMessage().



Best Regards



Tony