Cursor-based pagination support in Portainer REST API v2
0 reputation · 07 May 2024, 21:45 UTC
0 reputation · 07 May 2024, 21:45 UTC
When paginating through large collections such as endpoints or containers using the page and pageSize parameters, the API returns offset-based results with metadata including TotalCount and TotalPages. This approach works for static datasets but introduces consistency issues when resources are created or deleted between page requests.
The documentation does not clarify whether a cursor or token-based pagination mechanism exists to provide a stable snapshot across pages. Without such a mechanism, clients iterating over a changing collection may encounter duplicate entries or miss newly added items, especially when using the maximum pageSize of 100 across many pages.
Does Portainer's REST API v2 expose any cursor-based pagination option (for example, a cursor or after parameter) for collection endpoints? If not, are there recommended patterns—such as filtering by creation timestamp or using a specific version header—to achieve consistent iteration over mutating resources?
37275 reputation · 08 May 2024, 07:46 UTC
No. Portainer REST API v2 does not document a cursor, after, next-token, or pageToken parameter for collection endpoints such as endpoints or containers. Collection responses use offset-based pagination with page and pageSize, plus TotalCount and TotalPages metadata.
Each page request re-executes the underlying query against the current collection state. An offset of 100 on page two may point to a different resource after a deletion on page one, while newly inserted items can shift later offsets forward, causing repetition or omission across pages.
curl -s -H "Authorization: Bearer $PORTAINER_TOKEN" \
"https://portainer.example.com/api/v2/endpoints?page=1&pageSize=100" | \
python3 -m json.tool | head -n 40Inspect the response body for cursor, after, next, or pageToken fields. Then repeat the same request after creating or deleting one endpoint and compare whether entries shift, duplicate, or disappear. You can also open the running Portainer instance's OpenAPI/Swagger schema and search collection operations for pagination parameters beyond page and pageSize.
This answer assumes Portainer API v2 as currently documented in public releases. Behavior is version- and edition-sensitive; maximum pageSize and default page size are not confirmed here. Share your Portainer version and edition if you need edition-specific confirmation, since pagination behavior can differ between releases.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.