Loop through API data

Hi everyone, please excuse me while I try to adapt to the visual way…

I want to try and loop through some API data to see if I can find a value. Now in code I would find this realtaivly easy but I cant seem to figure out how to do it the wappler way.
So what I want to do is
Setup a Count Var
Get API data
Loop through data looking for the value increatement count vat by 1 for each item
Once I have found the value return true and exit out of the loop

How would I accomplish this in Wappler? Would this be a server side or a client side (or could it be either)?

Thanks for your help.

You can do this easily in server action.
Set count var using set value step.
Then, after api action, add a repeat action. Inside the repeat action set a condition action to check for the value you want and update the variable using set value.

If you just want the count of number of times a value exists in the API response, you can use where and count formatters in the client side.

If you are not familiar with the terms above, try searching for them in the community and docs. Else, post here again.

1 Like

Thanks sid I’ll try this tonight and get back to you

Hey @sid thanks for your suggestion earlier. What I am strugglig with on the server action is that it doesnt expand the array of items from the API to search through.

Heres the screenshot of the api from the server action you can see how it wont let me expand the items returned from the API.

Here’s the screenshot of the API from the client side

I am assuming what I want to do is do something like this with the repeat expression? ‘{{searchdata.data.items[count] .id.videoId==videoid}}’

Edit: I’ve just figure it out while reading another post. If i set the repeat to the API data then it allows me to access the items :slight_smile:

The array not expanding might be a bug. @Teodor might be able to explain on this better.

As for the repeat expression, it would just be the searchdata.data.items. Then inside the repeat, the condition step that you add will have the condition like id.videoid == videoid.

1 Like

Thanks SId, yeah when I set the repeat to the searchdata.data.items that allowed me to view the items and in there and select the videoid. My last question now is there a way to break out of the repeat when the condition is true. Thank you so much for all your help :slight_smile:

1 Like

No problem. Glad to see it working for you. :slight_smile:

Try using a return step where you wish to exit. Theoretically it should work, but haven’t tried this before.

1 Like

Thanks sid, I cant see a return step though?

Sorry, i meant to write RESPONSE step. :sweat_smile:

1 Like

Brilliant working 100% Thank you so much :smiley:

1 Like