1. Home
  2. Tutorials
  3. Working with APIs
  4. Filter API Array Values

Filter API Array Values

filtered pins
App showing pins only for places in the array with a particular price level range.

If you have an API request in your app that returns an array, you can filter the results before displaying them in the page. For example, you may want to test a particular field in each array entry to determine whether or how to display the data representing that item.

With a request returning an array added to a page in your app:

  1. Open the request Events and select the relevant status code (typically this will be 200: OK). Click the plus plus button to add an Action, selecting Iterate through Array. Edit the Action.
    • In the input, select the array from the API response, via the Event Data container. select array filter

    Save the Action.

  2. In the nested Item Event, add an Action, choosing If… Else.
    • In the first input, select the field from the array item that you want to test. if item field
    • In the center input, select an operator, for example to carry out a comparison test.
    • In the third input, select or enter a value to test the array item field against, which you can enter manually or pull from the sources in your app. greater than item
  3. In the nested True and False Events, add Actions to display your array fields depending on the result of the test, for example using Set Value.
    • Note that you may need to add more Actions before the If… Else in the Item Event to make your array fields accessible inside the True and False Events. Event Data is only available within the scope of the relevant Event. For example, this sequence of Actions filters locations returned from Google Places API, only displaying pins for array entries that meet a certain condition. iterate scope By saving the Item data to local variables in each iteration, the Actions inside the If… Else nested Events can access values for each place throughout the iteration. When adding new Actions to an Event, use the action arrows arrow buttons to set the order of execution.

You can also use status code Events to tailor page display to response fields that are not in arrays. To display images from an API array, use Element loaded Events. You can alternatively check for values in API array results and compare them, or carry out processing on a subset of the items. For more on location and mapping Actions, see the native functionality tutorials.

Was this article helpful to you? Yes No

How can we help?