Pagination
Paginated lists in the Nabto Cloud API return pagination links in the HTTP link
-header. From the first page on a list, the header will only contain a next
link. From the last page, only a prev
link exists. On pages between the first and last, both next
and prev
links exist. link
-headers contain a list of links in the following format (see actual examples in sections below):
link: <link1>; rel="relation1", <link2>; rel="relation2"
Link Headers
Next Header
On all but the last page, a link with the next
relation will be present, e.g.:
<https://api.cloud.nabto.com/v1/n5/products/pr-foobar/devices?cursor=de-foobar>; rel="next"
Previous Header
On all but the first page, a link with the prev
relation will be present, e.g.:
<https://api.cloud.nabto.com/v1/n5/products/pr-foobar/devices?cursor=de-foobar2>; rel="prev"
Example
To use this example, you must replace the product ID
, API key
and Organization ID
in the curl command with your own values from the Nabto Cloud Console.
Get a list of devices longer than 15:
$ curl 'https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?limit=5'\
-H 'accept: application/json, text/plain, */*' \
-H 'authorization: Bearer <YOUR API KEY>' \
-H 'x-nabto-organization: or-sjqpt9k7' \
-i
HTTP/2 200
content-type: application/json; charset=utf-8
content-length: 1230
date: Tue, 21 Mar 2023 08:55:10 GMT
x-powered-by: Express
access-control-allow-origin: *
access-control-expose-headers: link
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
link: <https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?deviceIdFilter=&limit=5&cursor=de-333ayark>; rel="next"
etag: W/"4ce-j9jZYJqsPd1YVdHgVMM1Grfc+Ys"
x-cache: Miss from cloudfront
via: 1.1 c45c96601bcfd826db9b745760473666.cloudfront.net (CloudFront)
x-amz-cf-pop: CPH50-P1
x-amz-cf-id: Yh6RBNcp9gckSIFREjnlDkIUNdi8pw_jl0Llhwv0BEO4Y_FKCGiL7g==
[... first page of devices ...]
Now extract the next
link from the link
header and execute it to get next page:
$ curl 'https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?deviceIdFilter=&limit=5&cursor=de-333ayark' \
-H 'accept: application/json, text/plain, */*' \
-H 'authorization: Bearer <YOUR API KEY>' \
-H 'x-nabto-organization: or-sjqpt9k7' \
-i
HTTP/2 200
content-type: application/json; charset=utf-8
content-length: 1231
date: Tue, 21 Mar 2023 08:57:55 GMT
x-powered-by: Express
access-control-allow-origin: *
access-control-expose-headers: link
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
link: <https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?limit=5&deviceIdFilter=>; rel="prev", <https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?deviceIdFilter=&limit=5&cursor=de-333ceyic>; rel="next"
etag: W/"4cf-JVL9XJHAzVsvAihIEZowu8kN4PQ"
x-cache: Miss from cloudfront
via: 1.1 7c56a1efd2427548060973d13fa756e2.cloudfront.net (CloudFront)
x-amz-cf-pop: CPH50-P1
x-amz-cf-id: k2vpHXNxdtqlMlhSKY0Xmt360mBTfnvcqEr6tio1QHibpb81AzoOQA==
[... second page of devices ...]
The link
-header now contains both next
and prev
links. We follow next
again:
$ curl 'https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?deviceIdFilter=&limit=5&cursor=de-333ceyic' \
-H 'accept: application/json, text/plain, */*' \
-H 'authorization: Bearer <YOUR API KEY>' \
-H 'x-nabto-organization: or-sjqpt9k7' \
-i
HTTP/2 200
content-type: application/json; charset=utf-8
content-length: 1230
date: Tue, 21 Mar 2023 08:59:46 GMT
x-powered-by: Express
access-control-allow-origin: *
access-control-expose-headers: link
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
link: <https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?cursor=de-333ayark&limit=5&deviceIdFilter=>; rel="prev", <https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?deviceIdFilter=&limit=5&cursor=de-333fjswh>; rel="next"
etag: W/"4ce-3Qjm7VB+aR3v8urb5hAbmajpshI"
x-cache: Miss from cloudfront
via: 1.1 623179a0437e8c560066525ff2e2167a.cloudfront.net (CloudFront)
x-amz-cf-pop: CPH50-P1
x-amz-cf-id: zSImQ7I4cIRzExS6sXcywrdiX9nDJ30_Lcc9NK9BL4Urqbb-o7qwJA==
[... third page of devices ...]
We can now follow the prev
link twice to get back to the first page:
$ curl 'https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?cursor=de-333ayark&limit=5&deviceIdFilter=' \
-H 'accept: application/json, text/plain, */*' \
-H 'authorization: Bearer <YOUR API KEY>' \
-H 'x-nabto-organization: or-sjqpt9k7' \
-i
HTTP/2 200
content-type: application/json; charset=utf-8
content-length: 1231
date: Tue, 21 Mar 2023 09:01:38 GMT
x-powered-by: Express
access-control-allow-origin: *
access-control-expose-headers: link
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
link: <https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?limit=5&deviceIdFilter=>; rel="prev", <https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?deviceIdFilter=&limit=5&cursor=de-333ceyic>; rel="next"
etag: W/"4cf-JVL9XJHAzVsvAihIEZowu8kN4PQ"
x-cache: Miss from cloudfront
via: 1.1 40e20db187b9959d3846f32db35de9bc.cloudfront.net (CloudFront)
x-amz-cf-pop: CPH50-P1
x-amz-cf-id: p8jot_4aQGEQZCtiQjtAGuO-OGxiuNL7sZpvzXwfVf8t1xQKZkYnmw==
[... second page of devices again ...]
$ curl 'https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?limit=5&deviceIdFilter=' \
-H 'accept: application/json, text/plain, */*' \
-H 'authorization: Bearer <YOUR API KEY>' \
-H 'x-nabto-organization: or-sjqpt9k7' \
-i
HTTP/2 200
content-type: application/json; charset=utf-8
content-length: 1230
date: Tue, 21 Mar 2023 09:03:00 GMT
x-powered-by: Express
access-control-allow-origin: *
access-control-expose-headers: link
x-frame-options: DENY
content-security-policy: frame-ancestors 'none'
link: <https://api.cloud.nabto.com/v1/n5/products/pr-cpphympt/devices?deviceIdFilter=&limit=5&cursor=de-333ayark>; rel="next"
etag: W/"4ce-j9jZYJqsPd1YVdHgVMM1Grfc+Ys"
x-cache: Miss from cloudfront
via: 1.1 78a128491ada170a2d9b82ba12d23d7a.cloudfront.net (CloudFront)
x-amz-cf-pop: CPH50-P1
x-amz-cf-id: 6nZgcuHn92OgwqhaBLaZSzy67LAloEoFE86ekWdhszEuyRVFp7f9sg==
[... first page of devices again ...]
Now that we are back at the first page, the prev
link is again not present in the link
-header.