Some of our API endpoints support fetching multiple objects, via paginated lists. The Fidel API uses cursor-based pagination via the 'start' and 'last' parameters.

A maximum of 100 objects can be returned per request and the limit can be specified by using the 'limit' parameter. By default, the 'limit' parameter is set to 100.

curl -X GET \
  https://api.fidel.uk/v1/programs/e1d96ed3-dfd6-4896-8e57-37dca8b1c394/transactions\?limit=10 \
  -H 'Content-Type: application/json' \
  -H 'Fidel-Key: sk_test_50ea90b6-2a3b-4a56-814d-1bc592ba4d63'

When the list is longer than the current page, a ‘last’ property is present on the response object. You can use that property to fetch the next page. To get the next page, you should set the 'start' property to the value of the 'last' property.

You'll need to stringify and URL encode the 'last' property before using it. Depending on your language and framework, that might be handled for you by default by your HTTP provider. Here's an implementation example using Node.js and request.

const request = require("request");

const FidelEndpoint = {
    url: "https://api.fidel.uk/v1/programs/e1d96ed3-dfd6-4896-8e57-37dca8b1c394/transactions?limit=1",
    headers: {
        'Content-Type': 'application/json',
        'Fidel-Key': "sk_test_50ea90b6-2a3b-4a56-814d-1bc592ba4d63"
    }
};

request.get(FidelEndpoint, (error, response, body) => {
    let json = JSON.parse(body);
    console.log(`First Page: ${body} \n`);

    console.log(`Making a request for the second page: ${FidelEndpoint.url}&start=${JSON.stringify(json.last)} \n`)

    request.get({
        url: `${FidelEndpoint.url}&start=${JSON.stringify(json.last)}`,
        headers: FidelEndpoint.headers
    }, (error, response, body) => {
        console.log(`Second Page: ${body}`);
    });
});

Because the request framework doesn't require the URL to be encoded, using JSON.stringify() for the last parameter is enough to get the second page. The same is not true for cURL, and if you'd want to replicate the same behaviour for fetching the second page, the last/start parameter needs to be URI encoded. Here's an example for running the same request to get the second page in cURL:

curl -X GET \
  https://api.fidel.uk/v1/programs/e1d96ed3-dfd6-4896-8e57-37dca8b1c394/transactions\?limit=1\&start=%7B%22programIdDel%22:%22e1d96ed3-dfd6-4896-8e57-37dca8b1c3940%22,%22id%22:%22aa21194a-2b14-4f56-aa17-c2463212ec53%22,%22time%22:%222020-08-27T13:37:45.317Z%22%7D \
  -H 'Content-Type: application/json' \
  -H 'Fidel-Key: sk_test_50ea90b6-2a3b-4a56-814d-1bc592ba4d63'

By default, the objects are returned in descending order by 'created' date. If you want to fetch the results in ascending order you can set the 'order' property with the value 'asc'.