@Rachel Cunninghamโ :
Sure, here's an example of a while loop that utilizes pagination with the API endpoint /jobs/runs/list/:
import requests
url = "https://api.example.com/jobs/runs/list/"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN"
}
params = {
"page_size": 10
}
has_more = True
while has_more:
response = requests.get(url, headers=headers, params=params)
response_json = response.json()
data = response_json["data"]
# Do something with the data
has_more = response_json["has_more"]
if has_more:
params["after_id"] = response_json["after_id"]
In this example, we first define the API endpoint URL, the required authorization headers, and the initial query parameters. We then set has_more to True to start the loop.
Inside the loop, we send a GET request to the API endpoint with the defined headers and query parameters. We then extract the data from the JSON response and do something with it.
We then check if has_more is True in the JSON response. If it is, we update the after_id query parameter with the value from the JSON response and continue the loop. If it is False, we exit the loop.
Note that the page_size parameter is used to control the number of results per page. You may need to adjust this value depending on your API endpoint's pagination behavior.