Filtering Repeat Duplicates in Nested API Data

Hi, I am using the amadeus API to get flights and (for roundtrip flights) I am trying to show the departing flight in an RG on the first page, then the user chooses one of the flights and gets directed to a second page that allows them to select a return flight.

There is one small issue. The API returns the departing and returning flights as one item (so there will be an itinerary which contains the nested departing flight and returning flight). Often times the API will return the same flight for multiple different flight combinations.
For example:
Itinerary 1
Departing Flight A,
Returning Flight B

Itinerary 2
Departing Flight A,
Returning Flight C

Itinerary 3
Departing Flight D,
Returning Flight B

So if I just list the Departing flights then the RG will show flight A twice and on the returning flight page the RG will list flight B twice. To make it even harder the itineraries are nested within the ‘data’ field.

Is there a way to filter the RG nested data? I have tried conditionals and filters but no luck so far.

Can you share how you have set your RG?
You could consider grouping or filtering depending of the JSON structure.

Thanks @Jici !
Yes, I have a group within the repeating group. Within the group I have things like ‘Where to where’ and ‘when to when’ all referencing the itinerary#1

Here is an example:

(The conditional is in case it has layovers)

The RG references the page’s custom state which holds the API data

API data is structured as so:
Segment (Flight):
Depart at
Segment (Flight):

I have tried filtering but I could not figure out how to filter nested JSON. I briefly looked at Grouping but I didn’t understand it but thought it wouldn’t help. How would you do it?

I’m not sure about the perfect solution and it would take time to investigate more by playing with data.
But one thing you could do is to set the API call result into a state.
Set your RG as a text and use the State to create a list of text with departure data (example: flight ID if this exist) and complete with :unique elements
To show data, you will use the State with :filtered function (maybe some advanced)

Ok awesome, I am not sure if I totally understand rn but will try to implement. I have always set RG type of content to flight data. I will try and lyk if I can find a way! thanks for the idea!!

1 Like