How to paginate using next_page_token

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?

1 Like

Hi @clchrist
Thanks for reaching out to us!
Here is a link to a post on how to use the next_page_token:

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

1 Like

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

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!