{"record":{"id":"dea07aa6dca3c4e9","repo":"flarum/framework","slug":"you-can-only-use-page-near-with-filter-discussion-and-the","errorCode":null,"errorMessage":"You can only use page[near] with filter[discussion] and the default sort order","messagePattern":"You can only use page\\[near\\] with filter\\[discussion\\] and the default sort order","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"framework/core/src/Api/Resource/PostResource.php","lineNumber":134,"sourceCode":"                ->defaultInclude([\n                    'user',\n                    'user.groups',\n                    'editedUser',\n                    'hiddenUser',\n                    'discussion'\n                ])\n                ->eagerLoad(['user.groups', 'discussion.state']),\n            Endpoint\\Index::make()\n                ->extractOffset(function (Context $context, array $defaultExtracts): int {\n                    $queryParams = $context->request->getQueryParams();\n                    $near = intval(Arr::get($queryParams, 'page.near'));\n\n                    if ($near > 1) {\n                        $sort = $defaultExtracts['sort'];\n                        $filter = $defaultExtracts['filter'];\n\n                        if (count($filter) > 1 || ! isset($filter['discussion']) || ($sort && $sort !== ['number' => 'asc'])) {\n                            throw new BadRequestException(\n                                'You can only use page[near] with filter[discussion] and the default sort order'\n                            );\n                        }\n\n                        $limit = $defaultExtracts['limit'];\n                        $index = $this->posts->getIndexForNumber((int) $filter['discussion'], $near, $context->getActor());\n\n                        return max(0, $index - $limit / 2);\n                    }\n\n                    return $defaultExtracts['offset'];\n                })\n                ->defaultInclude([\n                    'user',\n                    'user.groups',\n                    'editedUser',\n                    'hiddenUser',\n                    'discussion'","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/flarum/framework/blob/4b939f685389bfe8a380e9e28ddf305a1c66950c/framework/core/src/Api/Resource/PostResource.php#L116-L152","documentation":"Validation error raised in PostResource's Index endpoint offset extraction: page[near] (jump-to-post-number) is only meaningful when scoping posts to a single discussion via filter[discussion] and using the default sort order; any other combination would produce ambiguous or wrong offsets, so the request is rejected.","triggerScenarios":"Thrown at framework/core/src/Api/Resource/PostResource.php:134 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add filter[discussion]=<discussion id> to the query when using page[near]","Remove page[near] and use plain page[number]/page[size] pagination when listing all posts","Drop any custom sort parameter so the default sort order is used with page[near]"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4b939f685389bfe8a380e9e28ddf305a1c66950c","analyzedAt":"2026-09-15T18:09:20.879Z","contentChangedAt":"2026-09-15T18:09:20.879Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}