{"schemaVersion":1,"title":"Pagination and errors","url":"https://appgram.dev/docs/guides/api-requests","markdownUrl":"https://appgram.dev/docs/format-md/guides/api-requests.md","jsonUrl":"https://appgram.dev/docs/agent/pages/guides/api-requests.json","version":"current","locale":"en","markdown":"# Pagination and errors\n\nSend requests, handle response envelopes, and retry safely.\n\nUse the complete operation path from the reference. The API origin is `https://api.appgram.dev`; each operation defines its own parameters, authentication, and response shape.\n\n## Project context\n\nFor portal requests, include your public project ID when the operation declares `project_id`. A configured custom domain can supply project context in other flows. The generated portal examples include a project-ID placeholder so you can make a request without configuring a domain first.\n\nPath identifiers are resource-specific. A `status_page_id` is not a project ID, and a survey ID is not its public slug. Replace every placeholder in an example with the matching identifier.\n\n## Paginate feature requests\n\nThe public wish list accepts `page` and `per_page`:\n\n```bash\ncurl --get 'https://api.appgram.dev/portal/wishes' \\\n  --data-urlencode 'project_id=YOUR_PROJECT_ID' \\\n  --data-urlencode 'page=1' \\\n  --data-urlencode 'per_page=20'\n```\n\nIts documented response contains `success`, `data`, `page`, `per_page`, `total`, and `total_pages`. Treat a nullable `data` value as an empty list. Use the returned pagination metadata instead of assuming another page exists.\n\n```javascript\nconst url = new URL('https://api.appgram.dev/portal/wishes');\nurl.searchParams.set('project_id', 'YOUR_PROJECT_ID');\nurl.searchParams.set('page', '1');\nurl.searchParams.set('per_page', '20');\n\nconst response = await fetch(url);\nconst body = await response.json();\nif (!response.ok || body.success === false) {\n  throw new Error(body.error?.message ?? `HTTP ${response.status}`);\n}\n\nconst wishes = body.data ?? [];\nconst nextPage = body.page < body.total_pages ? body.page + 1 : null;\nconsole.log({ wishes, nextPage });\n```\n\nOther operations can return a plain array, a single object, or a different envelope. In particular, the monitor list returns an array. Do not apply the wish-list envelope to every endpoint. Blog feed endpoints return XML; read their declared media type before parsing.\n\n## Handle documented errors\n\nThe common JSON error schema is:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"ERROR_CODE_FROM_THE_RESPONSE\",\n    \"message\": \"A description of the failure\"\n  }\n}\n```\n\n`error.details` may also be present. The code above is a placeholder for the actual response code, not a complete error-code catalog. Check both the HTTP status and the documented error body. A proxy or network failure can return a non-JSON response, so production clients should handle parsing failures too.\n\nFor **401**, check credentials. For **403**, check project access and the scope named in the operation description. For **400**, check identifiers, required fields, and validation constraints. See [API authentication](/guides/api-authentication).\n\n## Retries and mutations\n\nUse bounded backoff for transient read failures and respect `Retry-After` when supplied. Do not immediately retry every failed request.\n\nA timeout on a mutation does not tell you whether the server completed it. Check the resulting resource before retrying creation or sending another message. Only use an idempotency header when the operation explicitly documents one.\n\n## Generated examples\n\nRequest and response examples illustrate the contract. Replace IDs, slugs, and credentials, and choose values that meet the operation's validation rules. They are not records from your project. HTTP examples in Swift or Dart are separate from the native [Swift](/ios-sdk) and [Flutter](/flutter-sdk) SDK APIs.\n\n","contentLocale":"en","isFallback":false,"authorship":{"authors":[],"contributors":[],"reviewedBy":[]}}