Pass the json input request payload to REST GET

Hello,
I am new to Snap logic, I am trying to create a pipeline where I need to pass the json input request payload. based on the input I have to check for condition and then route to TWO different REST GET calls.
my input json is like this
{
“state”: “sample_state”,
“count”: “sample_count”,
“Caller”: “sample_caller”,
“fromDate”: “sample_fromdate”,
“toDate”: “sample_todate”,
“SysId”: “sample_sysid”
}
how to pass this from external app. And how to read the values to pass to REST GET call.
Answer will help a lot. Thanks

Hi @arunnp,

You can pass data from external app by creating Triggered task.
This task can be created from Manager or from the Designers.

So these are the steps:

  1. Create Pipleline.
  2. Because the payload is in JSON format, get one JSON Parser snap and after that you can map the fields wherever you have Expression Builder.
  3. On the same pipeline on the right top corner click on Create Pipeline and select Triggered Task.
    image
    It will open up new window, click Save.
    After that go in Manager and go into the project where the pipeline is created and find the task(It will be the same name as the pipeline only the “Task” will be added in the name at the end. If you set different name search by that name), hover on the name of the task and it will show up arrow, click on the arrow and go in Details.
    Select the Cloud URL: this is the URL from where you will trigger the task also there is HTTP Header for authorization. You can authorize the call by Bearer Token or with Basic Authorization.

    On that url you can send the JSON payload.

I also attaching pipeline as example, but you will have to make the task on your own.
JSON_Payload_2021_08_02.slp (4.8 KB)

Here is one example triggering the pipeline above from Postman.
I am not doing anything just move the whole payload to Payload object and returning it back.

Regards,
Viktor

Thanks this helped me lot.
Once I get the input values I need to pass that to the REST get Service URL but the value is not passing.

I am doing like this


Here the caller is not getting replaced. I am getting empty response.
I tried {{$Caller}} still no response. I am missing proper syntax. can you pls help with proper syntax.
thanks

To get value from Caller field you first need to check the Expression Builder(=), and to get the value you need to make everything as string only the $Caller to be as expression.

For example from the image above need to look like this:

Hi, @arunnp

  1. The service url needs to start with “http(s)://” and then specify ble/incident. For example http://ble/incident
  2. For better reading of the URL, instead of concatenating the strings under Service URL, you can pass the input parameters under “Query parameters”. So depending how many query parameters will be used, you can add more by using +. See the example in the picture

Regards,
Angela.

@viktor_n replacing the field value using Expression Builder worked, but I guess my Service URL is long
I got error Invalid URI.
Later I tried with Query Parameters suggested by @angie it worked well
Thanks a lot for the your help.

1 Like

Hi @viktor_n, @angie

The response from REST GET I am mapping to a ‘result’ object but I am getting this inside array like below
[
{
“result”: [
{
“number”: “INC0029337”,
“short_description”: “test”,
“sys_id”: “90a4a74e1be97010ef9f6208b04bcb96”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
},
{
“number”: “INC0029347”,
“short_description”: “test”,
“sys_id”: “90a4a74e1be97010ef9f6208b04bcb96”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
}

    ]
}

]

but I need only the object inside. Ex
{
“result”: [
{
“number”: “INC0029337”,
“short_description”: “test”,
“sys_id”: “90a4a74e1be97010ef9f6208b04bcb96”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
},
{
“number”: “INC0029347”,
“short_description”: “test”,
“sys_id”: “90a4a74e1be97010ef9f6208b04bcb96”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
}

    ]
}

I tried some expressions in the mapper it is not working can you pls let me know how to get object as response. The below expression not giving desired oupput.

thanks
arun

Hi @arunnp,

Take one Splitter snap after the REST GET. In Json Path field which is in Splitter snap set the path of the result($entity.result)

Regards,
Viktor

Hi @viktor_n , thanks for reply
The Json Spliter splits the array, but it removes the array name in the output like below.
[{
“number”: “INC0029337”,
“short_description”: “test”,
“sys_id”: “erewrwer”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
},
{
“number”: “INC0029336”,
“short_description”: “testing 2nd incident”,
“sys_id”: “dfdsg”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:52:34”
}]
But the expected response should be like
{
“result”: [{
“number”: “INC0029337”,
“short_description”: “test”,
“sys_id”: “fsdfsdgsdg”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:53:28”
},
{
“number”: “INC0029336”,
“short_description”: “testing 2nd incident”,
“sys_id”: “sdgssf”,
“comments”: “”,
“state”: “2”,
“sys_updated_on”: “2021-07-26 10:52:34”
}
]
}
I tried to rap this using toObject but did not work. I guess snaplogic removing array name, but our backend code is expecting the response as “result” array of objects.

thanks
arun

There is one solution for this.

If you have one document that you are working with, then at the end of the pipeline, in the JSON Formatter just check the “Format each document”.

But if you have more than one document at the input of the JSON Formatter, in that case, first you will need to group the data with Group By snap(group size need to be 0) into one document and pass into the formatter.

Regards,
Viktor

@viktor_n thanks for the reply it worked after using JSON Formater.
Now I am trying to map the json fields in the output to different name which backend code is expecting

The input json
{
        "result": [
            {
                "number": {
                    "display_value": "INC0029337",
                    "value": "INC0029337"
                },
                "short_description": {
                    "display_value": "test",
                    "value": "test"
                },
                "sys_id": {
                    "display_value": "90a4a74e1be97010ef9f6208b04bcb96",
                    "value": "90a4a74e1be97010ef9f6208b04bcb96"
                },
                "comments": {
                    "display_value": "thh lafldsf. legmsfd",
                    "value": ""
                },
                "state": {
                    "display_value": "In Progress",
                    "value": "2"
                },
                "sys_updated_on": {
                    "display_value": "2021-07-26 16:23:28",
                    "value": "2021-07-26 10:53:28"
                }
            },
            {
                "number": {
                    "display_value": "INC0029336",
                    "value": "INC0029336"
                },

Here I need to map number.value → ticketNumber
short_description.display_value → description
sys_id.value → sys_id
comments.display_value → comments
state.display_value → status
sys_updated_on.value → lastUpdateTime

the final result array looks like


after re-map
{
        "result": [
            {
                "ticketNumber": "INC0029337",
                "description":  "test",                
                "sys_id":  "90a4a74e1be97010ef9f6208b04bcb96",
                "comments": "hello",
                "status": "In Progress",   ,
                "lastUpdateTime":  "2021-07-26 16:23:28"                   
            },
            {
                "ticketNumber": "INC0029337",
                "description":  "test",                
                "sys_id":  "90a4a74e1be97010ef9f6208b04bcb96",
                "comments": "hello",
                "status": "In Progress",   ,
                "lastUpdateTime":  "2021-07-26 16:23:28"                   
            },

Mapping like this becoming very difficult. There is no Json one to one mapping. Can you pls suggest mapping logic.
thanks
arun

Hi @arunnp ,

This can be done with the following steps:
image

  1. Add JSON Splitter after the input json and split on $result
    image

  2. Add a mapper to map the corresponding values ( you can easily map the values now since they are no longer in an array )

  3. And finally add a Group by N snap to group every object into a single array.
    image

Result:

  {
    "result": [
      {
        "ticketNumber": "INC0029337",
        "description": "test",
        "sys_id": "90a4a74e1be97010ef9f6208b04bcb96",
        "comments": "thh lafldsf. legmsfd",
        "status": "In Progress",
        "lastUpdateTime": "2021-07-26 10:53:28"
      },
      {
        "ticketNumber": "INC0029337",
        "description": "test",
        "sys_id": "90a4a74e1be97010ef9f6208b04bcb96",
        "comments": "thh lafldsf. legmsfd",
        "status": "In Progress",
        "lastUpdateTime": "2021-07-26 10:53:28"
      }
    ]
  }
]
1 Like

@j.angelevski it worked thanks a lot