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

Ignoring responses when an optional field is missing from the HTTP response

jfpelletier
New Contributor III

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

1 ACCEPTED SOLUTION

SpiroTaleski
Valued Contributor

@jfpelletier 

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. 

Spiro_Taleski_0-1699007151591.png

 

You can try that. 

BR,

Spiro Taleski

View solution in original post

4 REPLIES 4

SpiroTaleski
Valued Contributor

@jfpelletier 

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

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.

jfpelletier_0-1698946494516.png

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

SpiroTaleski
Valued Contributor

@jfpelletier 

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. 

Spiro_Taleski_0-1699007151591.png

 

You can try that. 

BR,

Spiro Taleski

jfpelletier
New Contributor III

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