---
updatedAt: 2025-09-17T22:29:07.000Z
agentTools:
  projectIndex: https://docs.vizionapi.com/llms.txt
---

# Use pagination to retrieve all references

```javascript JavaScript
const axios = require('axios');

const apiUrl = 'https://prod.vizionapi.com/references';
const perPage = 25;
const apiKey = 'YOUR_API_KEY_HERE'; // Replace with your actual Vizion API key

async function retrieveReferences(page = 1) {
  try {
    const response = await axios.get(apiUrl, {
      params: {
        include_metadata: true,
        page,
        limit: perPage,
      },
      headers: {
        'X-API-Key': apiKey,
      },
    });

    const { data, metadata } = response.data;

    // Process the data here (you can do whatever you need with the data)

    console.log(`Retrieved ${data.length} references from page ${page}`);

    // Check if there are more pages
    if (metadata.page < metadata.page_count) {
      // Retrieve the next page
      await retrieveReferences(page + 1);
    } else {
      console.log('All references retrieved successfully.');
    }
  } catch (error) {
    console.error('Error retrieving references:', error.message);
  }
}

// Call the function to start retrieving references
retrieveReferences();

```

```json Response Example
{"success":true}
```

# Import relevant libraries

<!-- javascript@1-1 -->

This step imports the Axios library, which is used for making HTTP requests. Axios simplifies the process of sending asynchronous HTTP requests with Node.

# Define the API endpoint and pagination parameters

<!-- javascript@3-5 -->

Here, the script defines the API URL, the number of items per page, and the API key. Make sure to replace 'YOUR_API_KEY_HERE' with your actual API key.

# Create function to retrieve references

<!-- javascript@7 -->

This step defines an asynchronous function named retrieveReferences that retrieves references from the API using pagination. The page parameter is set to 1 by default.

# Make request with Axios

<!-- javascript@9-18 -->

Here, Axios is used to make a GET request to the API with the specified parameters. The include_metadata parameter is set to true, and pagination parameters (page and limit) are included. The API key is passed in the headers for authentication.

# Process data and retrieve next page

<!-- javascript@20-40 -->

This step processes the data received from the API response. It logs the number of references retrieved and checks if there are more pages to retrieve. If more pages exist, the function calls itself recursively with the next page. If all pages have been retrieved, a success message is logged.

The code at the end initiates the retrieval process by calling retrieveReferences().