Example: Retrieving Drives
A comprehensive guide to retrieving a large batch of drives using the MileIQ External API
This guide demonstrates how to efficiently retrieve a large batch of drives using the MileIQ External API, including handling rate limits. We’ll use Python to showcase the process, but the principles can be applied to any programming language.
Prerequisites
Before you begin, make sure you have:
- A MileIQ API key
- Python 3.9 or later installed
- The
requests
library installed (pip install requests
) - The
pytz
library installed (pip install pytz
)
Pagination Explanation
It’s important to note that the MileIQ External API doesn’t use traditional offset/limit pagination. Instead, it uses a timestamp-based pagination method. To paginate through the results, you need to use the modified_before
and modified_after
parameters in conjunction with the has_more
field in the response body.
Here’s how it works:
- In your initial request, you set
modified_after
to the start of your desired date range andmodified_before
to the end of the range. - The API returns a batch of results and a
has_more
boolean indicating if there are more results to fetch. - If
has_more
is true, you make another request, but this time you setmodified_before
to themodified
timestamp of the last drive in the previous batch. - You repeat this process until
has_more
is false or you’ve retrieved all the drives you need.
This pagination method allows for efficient retrieval of large datasets while maintaining consistency even if new drives are added or modified during the pagination process.
Setting Up
First, let’s import the necessary libraries and set up our API configuration: