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;
}