cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Obtaining response from JSON Post command

peter
New Contributor III

Hi

I have a pipeline which takes data from a SQL select command and posts to a Service Now API to create a task. Service Now responds with the IDโ€™s of the tasks which I want to post back to the SQL.

However when I run the POST command in Snaplogic, I seem to get no response back, the circle is blank. I know the API has worked as I can see the tasks in Service Now and If I run the API command in Postman, I get the IDโ€™s returned.

How do I see the JSON response from the REST POST Snap?

22 REPLIES 22

RogerSramkoski
Employee
Employee

Hello Peter,

It sounds like you may be referring to viewing the response during pipeline validation, is that correct? If so, the REST POST snap is set to only run during full execution by default. You can change that setting at the bottom of the snap with the โ€œSnap Executionโ€ drop-down field which is shown below in the screenshot. As a general rule all of our write-capable snaps with the purple icon are set to only execute on โ€œExecute only.โ€

image

peter
New Contributor III

Super thank very much. That fixed it!

The data is returned in the following format;


"response": {statusLine:{, ...}, entity:{"result":{"status":"success","message":"Requested Item created: RITM1234569","record":"RITM1234569","sysid":"fb7f51d1dbaaaaaaa"}}, header...}

"original": {AutomationId:571, VersionNumber:2, Name:Get My Account, ShortDescription:Your account needs to be updated, SubmittedDate:{, ...}, url:Testurl2, type:Bot, Author:sveluswarm002, Inci...}

 {response:{, ...}, original:{, ...}}

{response:{, ...}, original:{, ...}}

In order to extract the Record and sysid in mapper I use the following:

Record = $response.entity.slice($response.entity.search("record")+9,$response.entity.search("record")+20)

Sysid = $response.entity.slice($response.entity.search("sysid")+9,$response.entity.search("}}")-1)

Is that the best way to extract the data from the string?

Thanks for all your help today!

dimche_saveski
New Contributor III

Hello @peter

You can use JSON Path to get the Record and sysid in the mapper. Write the path to the sysid location, try this in the mapper jsonPath($, โ€œ$entity.result.sysidโ€).

Best Regards
Dimche Saveski

peter
New Contributor III

Hi that is great, never thought of that!

Sadly I keep getting an error.

My string is.

[
{
โ€œresponseโ€:
{
โ€œstatusLineโ€:
{
โ€œprotoVersionโ€:
โ€œHTTP/1.1โ€
โ€œstatusCodeโ€:
200
โ€œreasonPhraseโ€:
โ€œOKโ€
}
โ€œentityโ€:
โ€œ{โ€œresultโ€:{โ€œstatusโ€:โ€œsuccessโ€,โ€œmessageโ€:โ€œRequested Item created: RITM1941111โ€,โ€œrecordโ€:โ€œRITM1941111โ€,โ€œsysidโ€:โ€œ60f3d2eadbe7041001โ€,โ€œautomation_idโ€:null,โ€œautomation_version_idโ€:null}}โ€

My command is, jsonPath($,โ€œ$response.entity.status.record.sysidโ€)

โ€œfailureโ€: โ€œExpecting object for JSON-Path field reference โ€˜statusโ€™, found: Stringโ€

Thanks for your help.