Obtaining response from JSON Post command

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?

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

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!

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

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.

Try 2 separate mappings. First one jsonPath(dollarSign,"$response.entity.result.record")
and second one jsonPath(dollarSign,"$response.entity.result.sysid")

Alternatively try these mappings
$response.entity.result.record
$response.entity.result.sysid

Regards
Dimche

The error seems to be related to data type being returned.

Peter

That maybe the case because there are quotation marks just after entity and before result field name, that are making it into string. Please check if this is original response from Service Now, or you have edited and added quotation marks by mistake.

Regards
Dimche

I use a SQL select command to pull data from a table and a REST post command to create a task record in ServiceNow. The response contains the direct response. which I then wish to match to the SQL data so that I can update the SQL table.

image .

Peter

I copied the response from above(just entity object), and mappings worked fine at my side. Can you please open your mapper and take screenshot so i can take closer look.

Thanks for your continued help!

and the output from the SNoW API is

My second issue is that the SNoW API POST Response returns three vales as numeric, but the response string shows them as NULL.

Peter

The mapping you have currently in the mapper is wrong, its trying to access object with name status , but status is a string . Delete that line and try this one instead:

$response.entity.result.sysid

Copy the line and try it, it should work.

The following gives me the string

However $response.entity.result.sysid fails

Peter

The problem is that entity object is a string, it should be JSON instead. I removed the quotation marks manually( the ones that are wrapping entity field value) and it worked instantly. Try JSON.parse($response.entity) function… That should make string into json

I nope get a a pair of red returned with no data.

Res square brackets [ ] .

Sorry, my spelling was awful.

I now get a red empty pair of red square brackets [ ]

GOT IT. Once I had saved the Snap it worked.

Thanks so much for your help.

The main problem was in the REST POST Snap, the response entity type was set to text, I switch this to default and it returned correctly formatted JSON, which I could extract.

Once again thanks for your help.

Glad to help solving the issue.

Regards
Dimche