REST pagination
Paginated REST API calls can be connected to a paginated Table.
To setup, click on the 'Pagination' tab of your REST Query.
Configuration
Pagination type:
- Page number based
- Cursor based
Pagination parameters location: The location that the paging parameters should be injected.
- Query params
- Request body
Param Conflicts
Make sure that the field names used in the Pagination tab do not conflict with any names used in the Params tab of your query.
Page Number Based | Cursor Based |
---|---|
Page number name: Query/Request Body field name for the page number | Request cursor name: Query/Request Body field name for the cursor token |
Page size name: Query/Request Body field name for the page size | Request limit name: Query/Request Body field name for the max results |
Response body name for cursor: Response Body field path for the next cursor token. This path will be taken directly from the API response before transformation |
Before and After Cursors
Some API's offer a before and after cursor. Budibase only takes a 'next' token, however as you iterate forward through the table, the tokens of the previous pages are automatically kept in memory and used when stepping backwards.
With that in mind, you could also use the API's 'before' token to paginate results in reverse order.
You can then select this query as the data source for a table, making sure the 'Paginate' checkbox is ticked.
Example: Recent Tweets
For this example, we will be using Twitter's recent tweets API as it supports cursor based pagination:
https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent
-
Create a new REST Datasource. Add in your Bearer token for Authentication.
-
Click Add query and input GET: https://api.twitter.com/2/tweets/search/recent
-
Add some query params:
- Add the pagination params:
- Exclude the meta data from the response using the transformer, and click 'Send'.
Under the Schema tab, undesired fields can be removed with the 'X'.
Then click 'Save'.
- Finally a paginated table can be created, linked to our query datasource:
Updated 11 months ago