1. Home
  2. Tutorials
  3. Working with APIs
  4. Check a Value in an API Array

Check a Value in an API Array

pin in iterateif in iterate

If you have an array of data returned from an API response and you want to check for particular values in it, you can do so using the Iterate through Array Action. With an API request returning the array (which will be listed in Dropsource as a Data Source) added to a page in your app:

  1. Open the request Events and open the Event the array will be sent with (typically this will be 200: OK). Click the plus plus button to add an Action, selecting Iterate through Array.
    • Select the array by name in the API response, via the Event Data container. select response array

    Save the Action.

  2. In the nested Item Event, add another Action, this time choosing If… Else.
    • In the first input, select the value from the array that you want to test, via the Event Data container. select iterate field
    • In the center input, select a comparison operator, for example == to test for equality with your next input.
    • In the last input, select a value to compare the array field against – this must match the type of the field. compare to true
  3. In the nested True and/or False Events, add whatever processing you want to execute when your test returns true or false for the array value. For example, you can update an Element in the page using the Set Value Action to indicate that a condition has been met. set text in iterate

You can display an array of map locations from an API using the iterate Action. If you want to display images from an array in an API response, you can do so using Element loaded Events. You can also use a conditional Action in conjunction with array iteration to filter results or to compare them. If you want to check a value from a response field that isn’t in an array, you can also use status code Events. You can alternatively carry out processing on the first n items in an array returned from an API.

Was this article helpful to you? Yes No

How can we help?