Impossible to paginate through GET/users with parameter "next_page_token"

Hello

I am building an OAuth for my users so they can get the list of users which have a license per country.
I am running the code below, it is working fine to reach page 1 and 2, but I am not able to reach page 3 to 7.

I have launched debug in Pycharm, but I have been with my head in the code for hours…

def get_users(access_token):
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'application/json'
    }
    URL_USERS = "https://api.zoom.us/v2/users?status=active&page_size=300"
    next_page_token = ""
    page_number = 1
    users_per_location = {}
    while True:
        if next_page_token:
            params = {'page_token': next_page_token, "page_number": page_number}
            response = requests.get(URL_USERS, headers=headers, params=params)
        else:
            response = requests.get(URL_USERS, headers=headers)
        page_number += 1
        response_json = response.json()
        for user in response_json['users']:
            if user['type'] == 2:
                try:
                    if user['timezone'].split("/")[1] in users_per_location:
                        users_per_location[user['timezone'].split("/")[1]] += 1
                    else:
                        users_per_location[user['timezone'].split("/")[1]] = 1
                except IndexError:
                    pass
        if 'next_page_token' in response_json:
            next_page_token = response_json['next_page_token']
        else:
            break
    print(users_per_location)
    return users_per_location

I have checked some other posts in this forum, and Zoom devs took example where they dont use “page_number” in parameters (but in my case it prevents me from breaking the while loop)

Any thoughts?

Hi @bwayan75
Thanks for reaching out!
If I am understanding correctly, you are not able to paginate through GET/users endpoint, using the next_page_token parameter?

Make sure that your parameter names match what Zoom expects to receive. The List users endpoint is documented as expecting the parameter name next_page_token, not page_token, so this line is suspicious:

2 Likes

Hello guys

I managed to make things work like this

    params = {
        "status": "active",
        "page_size": 300,
        "next_page_token": args[0] if args else ""
    }

And having in my function a *args as parameter def connect_with_tokens(access_token, *args):

This is solved

This topic was automatically closed 368 days after the last reply. New replies are no longer allowed.