Search…
Pagination
Provides the ability to separate and traverse through pages of data.
Some APIs provide the ability to query results in a paginated form. These APIs will typically have an optional nextToken input property to facilitate pagination. By default, if a limit is not provided, or set as nil/null, the default limit will be 10.
The following types support pagination:
    Funding Sources
    Virtual Cards
    Transactions
If intending to use pagination, the first call to an API should not include a nextToken, otherwise the result will return an error. When a paginated API call is successful, the output response will contain a nextToken property.
To access the next page of a query API, use the previously returned nextToken in the subsequent API call. If a successful response does not return a nextToken, or it is set to nil/null, the pagination results have been exhausted and there are no more pages to retrieve.
When using subsequent calls for pagination, ensure that the input information (e.g. limit, filter) is the same for each call, otherwise unexpected behavior will occur. For example, if the first call uses an input property of limit = 8, then each subsequent call must use a limit of 8.

Pagination Example

iOS
Below is an example usage of getFundingSourcesWithLimit for a user with 4 funding sources:
1
let semaphore = DispatchSemaphore(value: 0)
2
3
var output: ListOutput<FundingSource>?
4
client.getFundingSourcesWithLimit(2, nextToken: nil, cachePolicy: .remoteOnly) { result in
5
switch result {
6
case let .success(resultOutput):
7
/*
8
* This result will contain an `items` array of 2 Funding source objects, as
9
* well as a non-`nil` `nextToken` which is used in the subsequent call.
10
*/
11
output = resultOutput
12
semaphore.signal()
13
case let .failure(error):
14
// Handle and cleanup after error.
15
}
16
}
17
18
semaphore.wait()
19
20
client.getFundingSourcesWithLimit(2, nextToken: output?.nextToken, cachePolicy: .remoteOnly) { result in
21
switch result {
22
case let .success(resultOutput):
23
/*
24
* This result will also contain 2 objects in the `items` array, however the
25
* `nextToken` will be `nil`, as there are no more objects for the user to
26
* fetch.
27
*/
28
case let .failure(error):
29
// Handle and cleanup after error.
30
}
31
}
Copied!
DispatchSemaphore was used for simplifying the demonstration, we strongly recommend using GCD's Operation for handling asynchronous code.
Last modified 1yr ago
Copy link