I would recommend splitting the tasks into two parts, similar to what Michael has mentioned:
- The first part should be to return a list of all the devices you want and then store the devices in an object.
- Then you should run a loop that goes through each device in the object and makes another API call to return the device's trips.
Here is a link to our API reference guide:
I recommend looking at the following calls as they should help you return data relevant to what you are searching for: