{"record":{"id":"96cbd94c737c36f1","repo":"theonedev/onedev","slug":"count-should-not-be-greater-than-96cbd9","errorCode":null,"errorMessage":"Count should not be greater than ","messagePattern":"Count should not be greater than ","errorType":"validation","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/AgentTokenResource.java","lineNumber":79,"sourceCode":"\t@Path(\"/{tokenId}/agent\")\n    @GET\n    public Agent getAgent(@PathParam(\"tokenId\") Long tokenId) {\n    \tif (!SecurityUtils.isAdministrator()) \n\t\t\tthrow new UnauthorizedException();\n\t\tAgentToken token = tokenService.load(tokenId);\n    \treturn agentService.findByToken(token);\n    }\n\t\n\t@Api(order=200)\n\t@GET\n    public List<AgentToken> queryTokens(@QueryParam(\"value\") String value, \n    \t\t@QueryParam(\"offset\") @Api(example=\"0\") int offset, \n    \t\t@QueryParam(\"count\") @Api(example=\"100\") int count) {\n\t\tif (!SecurityUtils.isAdministrator())\n\t\t\tthrow new UnauthorizedException();\n\t\t\n    \tif (count > RestConstants.MAX_PAGE_SIZE)\n    \t\tthrow new NotAcceptableException(\"Count should not be greater than \" + RestConstants.MAX_PAGE_SIZE);\n\n\t\tEntityCriteria<AgentToken> criteria = EntityCriteria.of(AgentToken.class);\n\t\t\n\t\tif (value != null) \n\t\t\tcriteria.add(Restrictions.eq(AgentToken.PROP_VALUE, value));\n\t\t\n    \treturn tokenService.query(criteria, offset, count);\n    }\n\t\n\t@Api(order=500, description=\"Create new token\")\n    @POST\n    public Long createToken() {\n    \tif (!SecurityUtils.isAdministrator()) \n\t\t\tthrow new UnauthorizedException();\n\t\tAgentToken token = new AgentToken();\n\t    tokenService.createOrUpdate(token);\n\t\tauditService.audit(null, \"created agent token via RESTful API\", null, null);\n\t    return token.getId();","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/AgentTokenResource.java#L61-L97","documentation":"queryTokens enforces the platform-wide REST page-size limit: if the 'count' query parameter exceeds RestConstants.MAX_PAGE_SIZE, it throws NotAcceptableException with 'Count should not be greater than <MAX_PAGE_SIZE>'. This caps result payloads on list endpoints.","triggerScenarios":"GET /~api/agent-tokens?count=1000 (admin caller) where 1000 > RestConstants.MAX_PAGE_SIZE (typically 100).","commonSituations":"Bulk-export scripts requesting 'all' tokens with a huge count; copying a large limit from another API; off-by-order-of-magnitude pagination settings.","solutions":["Set count to RestConstants.MAX_PAGE_SIZE or less (e.g. count=100) and paginate using offset","Loop: request pages of count=100 incrementing offset until a page returns fewer results than requested","Filter with the value parameter to shrink the result set instead of fetching everything"],"exampleFix":"// before\nGET /~api/agent-tokens?offset=0&count=10000\n// after\nGET /~api/agent-tokens?offset=0&count=100\nGET /~api/agent-tokens?offset=100&count=100  // ...repeat until short page","handlingStrategy":"validation","validationCode":"final int MAX_PAGE_SIZE = 100; // RestConstants.MAX_PAGE_SIZE\nif (count > MAX_PAGE_SIZE) count = MAX_PAGE_SIZE; // clamp before calling","typeGuard":"int safeCount(int c) { return Math.min(c, 100); }","tryCatchPattern":"try { client.queryAgentTokens(value, offset, count); } catch (ClientErrorException e) { if (e.getResponse().getStatus() == 406) retryWithCount(offset, 100); }","preventionTips":["Always clamp count to RestConstants.MAX_PAGE_SIZE","Paginate with offset loops instead of large counts","Centralize page-size constants in API client code"],"tags":["rest-api","pagination","page-size","agent-token"],"backgroundTag":"invalid-query-parameter","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}