Pagination
Learn how to navigate through paginated responses.
Pagination helps manage large datasets from "List all" endpoints by breaking them into smaller pages using a cursor framework. Each page contains a subset of data, and the API response includes a link
header that provides the URL for retrieving the next set of results based on your current position.
The page size, or the number of items per page, varies by endpoint. Check the API reference for each endpoint to determine its specific page size.
Link
header format
Link
header formatWhen a response is paginated, the response header will include a link
header formatted as <URL>; rel="next"
, where:
URL
is the link to retrieve the next page of results. It includes anext
query parameter with an encoded token that preserves query parameters from the initial request, such as filters. These parameters will automatically apply to each subsequent page, ensuring consistency in the data returned.rel="next"
: This attribute specifies that the link is for the next page in the sequence.
You can only retrieve the next page of results. The previous or last pages cannot be accessed directly.
Pagination process
We'll use the List all courses endpoint to illustrate the pagination process. This endpoint can return up to 500 courses per page. If more courses exist, the API will split them across multiple pages.
Step 1: Make the initial request
Start by making a GET request to the paginated endpoint to retrieve the first page of published courses:
curl -i --request GET \
--url 'https://app.360learning.com/api/v2/courses?status[eq]=published' \
--header 'accept: application/json' \
--header '360-api-version: v2.0' \
--header 'authorization: Bearer your_access_token'
In this example:
-i
allows you to see the response headers along with the response body.status[eq]=published
specifies that only courses with a status of "published" should be returned.
Step 2: Check the response
You'll receive the first 500 courses in the body of the response.
- If there’s no
link
header, you’ve reached the last page. - If a
link
header is present, more pages available. Proceed to Step 3.
Example link header
link: <https://app.360learning.com/api/v2/courses?next=abcdef123456>; rel="next"
Step 3: Extract the URL
If you've received a response with a link
header, extract the URL enclosed in angle brackets:
https://app.360learning.com/api/v2/courses?next=abcdef123456
The next
query parameter will automatically preserve the initial filters, ensuring only published courses are retrieved on each page.
Step 4: Request the next page
Use the extracted URL to retrieve the next set of courses (i.e., courses 501–1000):
curl -i --request GET \
--url 'https://app.360learning.com/api/v2/courses?next=abcdef123456' \
--header 'accept: application/json' \
--header '360-api-version: v2.0' \
--header 'authorization: Bearer your_access_token'
The request returns only published courses.
Step 5: Repeat until complete
To retrieve additional pages, continue sending requests using the URL from the link
header in the previous response.
You can keep requesting more pages as long as the response includes a link
header.
When the response no longer includes a link
header, you’ve retrieved all available courses.
Updated 8 months ago