element-api
element-api copied to clipboard
Pagination No Longer Working after Update to v4.1.0
Description
After updating Element API to 4.1.0 the pagination on my endpoints no longer works. Following the "next" link to ?page=2
for example simply returns the page 1 results.
Here's my endpoint code:
return [
'endpoints' => [
'recipes.json' => function() {
$entryCriteria = [
'section' => 'recipes'
];
// filter by search query
$searchQuery = Craft::$app->request->getQueryParam('query');
if($searchQuery) {
$entryCriteria += [
'search' => $searchQuery,
'orderBy' => 'score'
];
}
// filter by category
$categoryQuery = Craft::$app->request->getQueryParam('category');
if($categoryQuery) {
$operator = ['and'];
$categoryList = explode(' ', $categoryQuery);
$entryCriteria += [
'relatedTo' => array_merge($operator, $categoryList)
];
}
return [
'elementType' => Entry::class,
'elementsPerPage' => 12,
'criteria' => $entryCriteria,
'resourceKey' => 'entries',
'transformer' => function(Entry $entry) {
return [
'id' => $entry->id,
'title' => $entry->title,
'uri' => $entry->uri,
'recipeImg' => $entry->recipeImg->one()->url
];
},
'pretty' => true
];
},
]
];
Steps to reproduce
- Update Element API from 3.0.1.1 to 4.1.0
- Access a query-string paginated page on your endpoint (for example:
my-site.tld/endpoint.json?page=2
)
Additional info
- Craft version: 4.8.6
- PHP version: 8.1.23
- Database driver & version: MySQL 8.0.33
- Plugins & versions: Amazon S3 2.2.1; Asset Rev 7.0.0; CKEditor 3.8.3; Super Table 3.0.12
Hi, thanks for reaching out! I’m unable to replicate this.
Do you have more than 12 entries matching the criteria? If I only have 12 entries, the results don’t show the pagination link on page 1, but if I manually edit the URL to request page 2, the results from page 1 will be returned.
Sorry for the late reply Iwona, this seems to have fixed itself. Thank you!
Thanks for confirming!