Pagination
When an endpoint returns more items than can be contained in a single response, the data is split and returned into multiple pages. By default, an endpoint returns 25 items per page —so if there are more than 25 items to return, the data will be split across pages.
Pagination in API v2 uses the same page and per_page parameters across every paginated endpoint.
You can change the default pagination by adding page and per_page parameters to your request:
page— the page number to return.per_page— the number of results to return per page. Maximum 100.
For example, your school might have 50 total courses. If you make a request to the /courses endpoint to fetch all courses, the return data will be split into multiple pages as you can only return 25 maximum items per page.
If you want to only return 5 items (i.e., courses) per page, you can add the per_page parameter to your request:
curl --request GET \
--url 'https://developers.teachable.com/v2/products/courses?per_page=5' \
--header 'Accept: application/json' \
--header 'apiKey: API-KEY-HERE'The request above would return data for the first page of items (i.e., the first 5 courses). You can then use the page parameter to adjust which page number to return. For example, adding a parameter page=2 to the above request would return the second page of courses (i.e., courses 6 through 10).
curl --request GET \
--url 'https://developers.teachable.com/v2/products/courses?page=2&per_page=5' \
--header 'Accept: application/json' \
--header 'apiKey: API-KEY-HERE'When an endpoint returns data across multiple pages, the return data will include a meta object that provides information on the pagination of the data:
- page - The current page
- per_page - The number of items displayed per page
- total_pages - The total number of pages
- total_count - The total number of items
This means that for our example call above, the meta object in the return data would be:
"meta": {
"page": 2,
"per_page": 5,
"total_pages": 10,
"total_count": 50
}Updated 8 days ago