Forum Discussion

peter's avatar
peter
New Contributor III
6 years ago

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?

22 Replies

  • 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.”

    • peter's avatar
      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's avatar
        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's avatar
    peter
    New Contributor III

    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.

    • dimche_saveski's avatar
      dimche_saveski
      New Contributor III

      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.

  • peter's avatar
    peter
    New Contributor III

    The following gives me the string

    However $response.entity.result.sysid fails

  • dimche_saveski's avatar
    dimche_saveski
    New Contributor III

    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

  • peter's avatar
    peter
    New Contributor III

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

      • peter's avatar
        peter
        New Contributor III

        Sorry, my spelling was awful.

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

  • peter's avatar
    peter
    New Contributor III

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

    Thanks so much for your help.

  • peter's avatar
    peter
    New Contributor III

    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.

    • dimche_saveski's avatar
      dimche_saveski
      New Contributor III

      Glad to help solving the issue.

      Regards
      Dimche

  • RavNeu's avatar
    RavNeu
    New Contributor II

    I am trying to achieve similar goal. I put the file writer after JSON Formator snap to see the output format.
    below is the output I am getting:

    {
    “response”: {
    “statusLine”: {
    “protoVersion”: “HTTP/1.1”,
    “statusCode”: 200,
    “reasonPhrase”: “OK”
    },
    “entity”: {
    “document”: {
    “id”: “time_to_salesforce”,
    “rows”: [{
    “row”: {
    “rsId”: “XT_MF_TM_SF_1”,
    “data”: {
    “XT_EMPLOYEE_ID”: “A00000”,
    “XT_ENTERED_HOURS”: 8,
    “XT_FIRST_NAME”: “XXXXX”,
    “XT_GLC_ID”: “XXX”,
    “XT_HOURS_DATE”: “2022-09-30T00:00:00”,
    “XT_LAST_NAME”: “XXX”,
    “XT_MODIFIED_BY”: “100000000”,
    “XT_PAYROLL_EMPLOYEE_ID”: “X000000”,
    “XT_PAY_TYPE”: “R”,

    I want to load this into sql server table, so I used mapper after JSON Parser. Below is the expression I used in mapping source side:
    JSON.parse($response.entity.document.rows[0].row.data.XT_EMPLOYEE_ID)
    But it says unable to parse JSON value.

    what expression should i use to pick this field and load into sql table?

    Also, I got my response as an array rows. So, how will i be able to pick all the rows within the array?

    thank you for your response in advance!!

    • RogerSramkoski's avatar
      RogerSramkoski
      Employee

      Hi @RavNeu, are you able to provide a screenshot of your pipeline? Just from the description alone it sounds like you want a JSON Formatter Snap before the Mapper to split on the rows array so each row becomes it’s own document. For example, if you have some data like this:

      You could use a JSON Splitter to split on ‘jsonPath($, “response.entity.document.rows[*]”)’:

      Then your Mapper could be configured like this:

      Here is the short pipeline I built to demonstrate this in case it helps you to import it and visualize it:
      QuickJSONArraySplitExample_2023_05_16.slp (5.5 KB)