11-01-2023 11:39 AM
Hello all,
I have a HTTP Client snap that returns an array of JSON in the response, and I need to use the data from the JSON responses in the next HTTP Client only if a certain key "file" is present in the initial response. If the key is present in the JSON, I need to use the value in the next snap, but if the key is missing, I do not need to do anything.
So from a HTTP response, how can I filter the results to ignore them when this key "file" is missing?
Thanks in advance!
JF
Solved! Go to Solution.
11-03-2023 03:18 AM - edited 11-03-2023 03:25 AM
I think that "join" snap can be avoided here, as after the second call(to get the files) you will get the JSON with the project details under the "original" object.
You can try that.
BR,
Spiro Taleski
11-02-2023 01:56 AM
If the first HTTP Client always returns Array with only one element, then you can convert that Array into String and then route the record to the next HTTP Client(depending if "file" key is present or not), using Router Snap.
If first HTTP Client returns Array with multiple elements, and you need to check every element, then the best is to split that Array using JSON Splitter Snap and route the records using Router Snap, based on that presence of the "file" key field.
BR,
Spiro Taleski
11-02-2023 10:41 AM
Hello @SpiroTaleski,
Thanks very much for your reply! It works for a simple case, however I realized that my use case might be a bit more complex. Here's with a bit more details...
In the initial JSON that I'm getting from the HTTP Client call, which is an array of JSON objects, I have to keep and use at least two elements from the initial response. The array contains JSON objects that describe a project, including values such as the project name, it's ID, and other elements that I might need at some point. It does not however contain the JSON with the potential "file" key that I also need, I have to do another call for that, using the "id" that I got from the first call.
Please have a look at the illustration below. It shows the process where I need to first get the project name and ID of each project on a server, then using the value of the ID I need to make another call to get the file name(s) and path(s) if they exist. If there is no file in the project, then no action is required.
I think that I would need to use a "join" snap to create a new JSON as new payload for the next call, with a condition (set by the router) that would consider only when the "file" element exists, correct? Or is there a better way?
Thanks a lot again!
JF
11-03-2023 03:18 AM - edited 11-03-2023 03:25 AM
I think that "join" snap can be avoided here, as after the second call(to get the files) you will get the JSON with the project details under the "original" object.
You can try that.
BR,
Spiro Taleski
11-03-2023 08:51 AM
You are absolutely right, @SpiroTaleski!
That works for me, I'm getting exactly what I need after the second call as you mentioned! 🙂
Thanks for your help!
JF