# Next Page Token Issue

**URL:** <https://devforum.zoom.us/t/next-page-token-issue/93775>\
**Category:** Meetings\
**Tags:** api\
**Created:** [August 22, 2023, 1:14pm UTC](https://devforum.zoom.us/t/next-page-token-issue/93775 "2023-08-22T13:14:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffblackwood86](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jeffblackwood86](https://devforum.zoom.us/u/jeffblackwood86)\
**Post date:** [August 22, 2023, 1:14pm UTC](https://devforum.zoom.us/t/next-page-token-issue/93775/1 "2023-08-22T13:14:47Z")

</div>

Strange behaviour with pagination. My request is returning accurate next page tokens which seem to be used in subsequent requests, but the response is repeating the first page over and over instead of the next page of data. I’m using GAS and this is part of an automated attendance flow. However this is a huge issue as we are not able to fetch participants last leave time, thus we are unable to accurately track attendance.

function processPageData(next\_page\_token, previous\_page\_token = “”) {  
// If we’ve processed all participants, return immediately  
if (participants\_processed\_count \>= fullMeetingData.participants\_count) {  
console.log(“All participants processed, breaking the loop.”);  
return;  
}

```
// Fetching a single page of participant data
var pageData = getZoomMeetingReportPageData(todaysInstance.uuid, next_page_token);

// Log the current and previous next_page_token
console.log(`Previous next_page_token: ${previous_page_token}`);
console.log(`New next_page_token from current response: ${pageData.next_page_token}`);

// Process the exact number of participants' data returned by the API
processMeetingParticipantsPageData(fullMeetingData, pageData, participantToDurationMap, pageData.participants.length);

// Update participants_processed_count
participants_processed_count += pageData.participants.length;

// Log the current state of the loop
console.log(`Processed ${participants_processed_count} out of ${fullMeetingData.participants_count} participants.`);

// Check if the next_page_token exists and is different from the previous one
if (pageData.next_page_token && pageData.next_page_token !== previous_page_token) {
    processPageData(pageData.next_page_token, next_page_token);
} else {
    console.log("No new next_page_token received or same token received. Exiting recursion.");
}

```

}

function getZoomMeetingReportPageData(meetingUUID, next\_page\_token) {  
// Double check encoding  
var encodedUUID = encodeURIComponent(meetingUUID);  
var url = `https://api.zoom.us/v2/past_meetings/${encodedUUID}/participants?page_size=50&page_token=${next_page_token}`;

```
Logger.log('Request URL: ' + url); // Log the request URL

// (Sensitive part related to authorization removed for security)
var options = {
    'headers': {
        'Authorization': 'Bearer ' + '[YOUR_ZOOM_ACCESS_TOKEN]'
    },
};

var response = UrlFetchApp.fetch(url, options);

if (response.getResponseCode() !== 200) {
    Logger.log('Error fetching data from Zoom API. Response Code: ' + response.getResponseCode());
    throw new Error('Error fetching data from Zoom API.');
}

var jsonData = JSON.parse(response.getContentText());

if (jsonData && jsonData.participants) {
    Logger.log(`Received ${jsonData.participants.length} participants from Zoom API for this page.`);
    if (jsonData.participants.length > 0) {
        Logger.log(`First participant of the page: ${jsonData.participants[0].name}`);
        Logger.log(`Last participant of the page: ${jsonData.participants[jsonData.participants.length - 1].name}`);
    }
} else {
    Logger.log('Unexpected response format from Zoom API or failed request.');
}

// Checking for duplicate participants
var namesEncountered = new Set();
jsonData.participants.forEach(participant => {
    if (namesEncountered.has(participant.name)) {
        Logger.log(`Duplicate participant found: ${participant.name}`);
    } else {
        namesEncountered.add(participant.name);
    }
});

var participantsData = {};
for (var i = 0; i < jsonData.participants.length; i++) {
    var participant = jsonData.participants[i];
    if (participantsData[participant.name]) {
        participantsData[participant.name].join_time = Math.min(participantsData[participant.name].join_time, new Date(participant.join_time).getTime());
        participantsData[participant.name].leave_time = Math.max(participantsData[participant.name].leave_time, new Date(participant.leave_time).getTime());
    } else {
        participantsData[participant.name] = {
            'join_time': new Date(participant.join_time).getTime(),
            'leave_time': new Date(participant.leave_time).getTime()
        };
    }
}

jsonData.participantsData = participantsData;

return jsonData;

```

}

---

<div class="post-metadata">

**Author:** ![elisa.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/elisa.zoom/32/47836_2.png) [@elisa.zoom](https://devforum.zoom.us/u/elisa.zoom)\
**Post date:** [August 24, 2023, 6:39pm UTC](https://devforum.zoom.us/t/next-page-token-issue/93775/2 "2023-08-24T18:39:12Z")

</div>

Hi @jeffblackwood86  
Thanks for reaching out to us! I am happy to help here!  
So basically, when you get a next\_page\_token and you use it to get the rest of the data, the requests bring back the exact same data? it is not bringing you the next records in the response?  
Also is this an issue that just started or have you been noticing this in the past?

---

<div class="post-metadata">

**Author:** ![jeffblackwood86](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jeffblackwood86](https://devforum.zoom.us/u/jeffblackwood86)\
**Post date:** [August 24, 2023, 7:50pm UTC](https://devforum.zoom.us/t/next-page-token-issue/93775/3 "2023-08-24T19:50:46Z")

</div>

Hi @elisa.zoom,

Thank you so much for your reply. It has behaved this way since the beginning, and it is the last hurdle before this automated attendance app will be fully functional. It seems to just provide the same first page over and over again even though the next page tokens are different.

Any suggestions or insights would be appreciated! I am knew to coding but trying to learn as best I can.

Thank you again,  
Jeff

---

<div class="post-metadata">

**Author:** ![elisa.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/elisa.zoom/32/47836_2.png) [@elisa.zoom](https://devforum.zoom.us/u/elisa.zoom)\
**Post date:** [August 24, 2023, 8:14pm UTC](https://devforum.zoom.us/t/next-page-token-issue/93775/4 "2023-08-24T20:14:10Z")

</div>

Interesting, @jeffblackwood86  
Here is a helpful post on how to handle next\_page\_token with recursion

> [@Handling paginated responses from the Zoom API](https://devforum.zoom.us/t/handling-paginated-responses-from-the-zoom-api/68825):
>
> 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 …

I will also go ahead and send you a private message to get more details about your specific case  
Cheers,  
Elisa
