clchrist
(Conrad)
April 20, 2023, 7:25pm
1
API Endpoint(s) and/or Zoom API Event(s): https://api.zoom.us/v2/phone/numbers
https://developers.zoom.us/docs/api/rest/reference/phone/methods/#operation/listAccountPhoneNumbers
I have a working API for Phone Numbers that is connecting and returning the first page of results with a next_page_token, page_size, and total_records. I have tried a few things but the next_page_token does not paginate through the additional pages of data. It continues returning the first page.
How is next_page_token used to paginate through all the pages in Python?
Hi @clchrist
Thanks for reaching out to us!
Here is a link to a post on how to use the next_page_token:
When an API response contains more data than can be returned in a single page, the API will return with a token to request the next page of results.
But how will you expect to receive a paginated response? If your response contains a next page token, make the same request again using that token as a query parameter.
Say you have 70 users on your account, as in, more than the default page size of 30. A request to the list users will initially respond with 30 users. To get the full list, you’ll …
If this continues to be an issue that you are not getting the last page, please let me know and I can take a closer look
Cheer,
Elisa
To paginate through all the pages using the next_page_token parameter in Python, you can use a loop to make subsequent requests until all pages have been retrieved. Here is an example code snippet:
import requests
Set up initial request parameters
url = “https://api.zoom.us/v2/phone/numbers ”
params = {
“page_size”: 50 # Set the desired page size
}
Make the initial request and retrieve the first page of results
response = requests.get(url, params=params)
data = response.json()
next_page_token = data.get(“next_page_token”)
Loop through subsequent pages until all pages have been retrieved
while next_page_token:
# Add the next_page_token to the request parameters
params[“next_page_token”] = next_page_token
# Make the request for the next page of results
I hope it’ll help.
Thanks for chiming in @charles1237718
clchrist
(Conrad)
April 25, 2023, 10:03pm
5
Thank you, Ahmed charles1237718 . Very helpful. I have tried several different similar approaches and I haven’t been able to get it working yet.
Here is my initial code retrieving the first page only (minus the writeJSONfile snip):
import requests
import json
access_token = “working_token”
url = “https://api.zoom.us/v2/phone/numbers ”
headers = {
“Authorization”: f"Bearer {access_token}",
“Content-Type”: “application/json”,
}
response = requests.get(url, headers=headers)
Could you clarify the structure including your suggestions?
Thank you!