Pagination

 

The Codat API uses a simple set of query parameters on data endpoints to facilitate paging through large amounts of data.

Request

Our data endpoints which return multiple results are paged. You will need to supply a page query parameter when calling these endpoints. You can configure the size of each page by using the pageSize query parameter.

  • page : This is the page number that you would like.
  • pageSize : This is the size of the results set you would like (default: 100).

Response

{
    "results": [
        // This will be an array of the specified data type
    ],
    "pageNumber": 1,    // Current page number
    "pageSize": 1,      // Current max size for the page
    "totalResults": 1,  // Total number of records in the result set
    "_links": {         // HAL links
        "self": "",     // Direct link to the dataset 
        "current" : "", // URL for the Current page
        "next": "",     // URL for the next page (where applicable)
        "previous": ""  // URL for the previous page (where applicable)
    }
}

You can use the totalResults and pageSize to calculate the number of pages that will be required to retrieve all of the available data.

Note: totalResults returns the number of results after applying any query which was provided.

Example

GET /companies/{companyId}/data/invoices?page=1&pageSize=100
var query = new InvoicesQuery(companyId, 
                    /* filter query */ null, 
                    /* page number  */ 1, 
                    /* page size    */ 100)
                .run(codat.uat(apiKey));

// Following of the pages directly from the HAL links is not yet supported by the client library.
var request = new RestRequest("companies/{companyId}/data/invoices", Method.GET);
request.AddUrlSegment("companyId", companyId);
request.AddQueryParameter("page", 1.ToString());
request.AddQueryParameter("pageSize", 100.ToString());
request.AddHeader("Authorization", $"Basic {encodedApiKey}");
var response = client.Execute(request);
var info = response.Data;