Can't figure out how to get last page of data

Hi all,

Apologies in advance if this question has already been asked.

I’m using Python to paginate through all recordings for a user (/users/{userId}/recordings). I’ve looped through all the pages using the next_page_token value. So far it works, but I encounter a problem with grabbing records from the last page of results.

For example, we have a user with 64 recordings. That’s 3 pages of JSON data (30, 30, 4), since each page returns a maximum of 30 records. The first two pages of records are gathered, but not the last one with 4 records. I suspect this is because on the last page of data, the value of next_page_token is empty (e.g. "next_page_token": ""), and this causes my while loop to stop before it can grab the last page of records.

Here’s my code:

while recordings_data['next_page_token']:
    payload = { 
          'userId': 'user@site.com', 
          'from': '2020-01-01', 
          'next_page_token': recordings_data['next_page_token'] 
          }
    response = requests.get(url="https://api.zoom.us/v2/users/user@site.com/recordings", headers=AUTHORIZATION_HEADER, params=payload)
    recordings_data = response.json()
    recordings.extend(recordings_data['meetings'])
    return recordings

Many thanks for the help!

Hi rrodrigues,

I have similar code in PHP and solved it by using the array count on recordings_data for the while condition instead of the next_page_token existence. Here’s the php version which should translate pretty easily:

// initial request
$request = new ListAccountRecordingsRequest();
$request->setPageSize(300)
    ->setFrom('2020-02-02');
    
$response = $zoom->execute($request);
$recordings = $response->getRecordings();
$token = $response->getNextPageToken();

while ( count($recordings) > 0 ) {

    [ some processing ]]]

    if ( $token ) {
        // we have another page
        $request->setNextPageToken($token);
        $response = $zoom->execute($request);
        $recordings = $response->getRecordings();
        $token = $response->getNextPageToken();
    } else {
        // nothing left to grab
        $recordings = array();
    }
}

Hope this helps!

-Roberto

1 Like

Thanks for this. I’ll try to port your code over and see if it works.

Ok, I eventually figured it out after debugging my code.

The problem wasn’t because the next_page_token key was empty on the last page of results like I had originally assumed. It was because I wasn’t updating the next_page_token variable with the new key. Foolish mistake!

Working code below:

for i in range(1, page_count):  # start at page index 1 since we already have the first page
    payload = { 'userId': email, 'from': RECORDING_START_DATE, 'next_page_token': next_page }
    response = requests.get(url=API_ENDPOINT_RECORDING_LIST(email), headers=AUTHORIZATION_HEADER, params=payload)
    recordings_data = response.json()
    next_page = recordings_data['next_page_token'] # update with new token
    recordings.extend(recordings_data['meetings'])

return recordings
1 Like

Glad this is working @rrodrigues! Let us know if you need any help.

Thanks for your help @robertom!