# Handling paginated responses from the Zoom API

**URL:** <https://devforum.zoom.us/t/handling-paginated-responses-from-the-zoom-api/68825>\
**Category:** API and Webhooks\
**Tags:** guide\
**Created:** [May 12, 2022, 1:50am UTC](https://devforum.zoom.us/t/handling-paginated-responses-from-the-zoom-api/68825 "2022-05-12T01:50:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/michael.zoom/32/37213_2.png) [@michael.zoom](https://devforum.zoom.us/u/michael.zoom)\
**Post date:** [May 12, 2022, 1:50am UTC](https://devforum.zoom.us/t/handling-paginated-responses-from-the-zoom-api/68825/1 "2022-05-12T01:50:37Z")

</div>

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 need to make three requests (30, 30, then 10).

Requesting [https://api.zoom.us/v2/users](https://api.zoom.us/v2/users) for the first time, you’ll see a `next_page_token` in the response body. This indicates you’ll need to make subsequent requests.

The first request returns 30 users:  
GET `https://api.zoom.us/v2/users`

Response:

```json
{
  page_count: 3,
  page_number: 1,
  page_size: 30,
  total_records: 70,
  next_page_token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaa', // for example
  users: [] // count: 30
}

```

The second request returns 30 users:  
GET `https://api.zoom.us/v2/users&next_page_token=aaaaaaaaaaaaaaaaaaaaaaaaaaa`

Response:

```json
{
  page_size: 30,
  total_records: 70,
  next_page_token: 'bbbbbbbbbbbbbbbbbbbbbbbbbbb', // for example
  users: [] // count: 30
}

```

The third request returns 10 users:  
GET `https://api.zoom.us/v2/users&next_page_token=bbbbbbbbbbbbbbbbbbbbbbbbbbb`

Response:

```json
{
  page_size: 30,
  total_records: 70,
  next_page_token: '', // no token is returned in the final response
  users: [] // users.length = 10
}

```

> Many Zoom API endpoints, including from users API, will allow you to set larger page sizes up to 300 results.

### Handling pagination through recursive functions

In JavaScript, this can be handled using [recursive functions](https://developer.mozilla.org/en-US/docs/Glossary/Recursion) to handle larger responses conditionally. Below is an example of handling responses in NodeJS.

```javascript
// https://www.npmjs.com/package/axios
import axios from 'axios'

// example headers for authorization
const headers = {
	headers: {
		"Content-Type": "application/json",
		Authorization: "Bearer " + YOUR_ACCESS_TOKEN,
	},
};

// For this sample, we'll manually set page size in the URL to force pagination.
let manualPageSize = 2;
let baseURL = `https://api.zoom.us/v2/users?page_size=${manualPageSize}`;

// Create a function that takes in the endpoint and the initial/current array of users
const getUserList = (url, userArray) => {
  axios.get(url, headers).then((response) => {
    const retrievedUsersArray = userArray.concat(response.data.users);
    if (response.data.next_page_token) {
      let nextPath = `${baseURL}&next_page_token=${response.data.next_page_token}`;
      return getUserList(nextPath, retrievedUsersArray);
    } else {
      return retrievedUsersArray;
    }
  });
};

// Call the function using the base URL (without next_page_token) and an empty array
getUserList(baseURL, []);

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [June 11, 2022, 11:51am UTC](https://devforum.zoom.us/t/handling-paginated-responses-from-the-zoom-api/68825/2 "2022-06-11T11:51:03Z")

</div>

Closed on June 11, 2022, 11:51am UTC

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