Pagination

Using Pagination in the API with Query Parameters

When dealing with large responses, the API paginates results to make responses more manageable. To retrieve specific pages of data, you can use query parameters in the request URL.

Key Pagination Fields in the Response

  • count: Total number of items available across all pages.

  • next: URL for the next page of results, if available. This will be null if you’re on the last page.

  • previous: URL for the previous page of results, if available. This will be null if you’re on the first page.

  • results: List of data items for the current page.

Query Parameters

  1. page: This parameter allows you to request a specific page of results.

  2. page_size: This parameter defines how many items should be returned per page. If not specified, the API will use a default value.

Example Response

{
  "count": 123,
  "next": "http://saas.haut.ai/api/v1/companies/{company_id}/datasets/?page=4&page_size=10",
  "previous": "http://saas.haut.ai/api/v1/companies/{company_id}/datasets/?page=2&page_size=10",
  "results": [
    // Data for the current page
  ]
}

How to Use Pagination with Query Parameters:

  1. Initial Request:

    • By default, the API returns the first page of results. You can control the number of results per page with the page_size parameter.

    • Example request for the first 10 results:

      curl -X GET "http://saas.haut.ai/api/v1/companies/{company_id}/datasets/?page=1&page_size=10"
  2. Navigating to the Next Page:

    • To retrieve the next page of results, use the URL in the next field or set the page parameter manually.

    • Example:

      curl -X GET "http://saas.haut.ai/api/v1/companies/{company_id}/datasets/?page=4&page_size=10"
  3. Going Back to the Previous Page:

    • Similarly, you can use the previous field or specify the page in the request URL to go back.

    • Example:

      curl -X GET "http://saas.haut.ai/api/v1/companies/{company_id}/datasets/?page=2&page_size=10"
  4. Customizing Page Size:

    • If you need more or fewer items per page, use the page_size parameter to control how many results are returned on each page.

    • Example for 25 results per page:

      curl -X GET "http://saas.haut.ai/api/v1/companies/{company_id}/datasets/?page=1&page_size=25"

Handling Edge Cases:

  • next is null: You’re on the last page of results.

  • previous is null: You’re on the first page of results.

Last updated