Handle REST API errors and pagination
Process page-number results without skipping files, classify Dosya API failures by status and body, and retry only operations that are safe to repeat.
Last reviewed
A reliable client treats paging state, authentication failures, authorization refusals, conflicts, and transient limits as different outcomes. Dosya does not use a continuation token for file lists.

Response model
Successful JSON normally includes ok:true. Failures normally use { "ok":false, "error":"…" }; structured errors such as folder_locked can add fields. Preserve the HTTP status and the complete error body in redacted logs.
GET /api/files uses page and per_page. The response’s pagination object supplies page, per_page, total_files, and total_pages.
Steps
- Request page 1 with a stable workspace, folder, filter, sort, and
per_page, then keep those query values unchanged for the run. - Process each file by
id, store the current numeric page, and readpagination.total_pagesfrom the same response. - Increment
pageuntil the processed page equalstotal_pages; do not look for a cursor, continuation, ornext_pagefield. - On a non-success response, record status,
error,Retry-After, and rate-limit headers without storing the bearer key. - Retry 429 and retryable 503 responses after
Retry-After; repeat GET, HEAD, or a documented multipart-part retry, but inspect state before replaying a mutation. - Reconcile processed file ids at the end, leaving unresolved failures visible rather than marking the whole page complete.
Status and timing rules
401 Invalid or expired API key calls for credential or expiry investigation. A transient authentication lookup instead returns 503 Service temporarily unavailable with Retry-After: 5. A 403 can come from scope, surface, workspace pin, role, lock, or another access rule. A 404 may intentionally conceal a hidden or confined resource. A 409 reports a state conflict. A 429 body says Too many requests.
Most API responses expose X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset. Authenticated file-list polling receives a 600-per-minute user tier and still passes the 600-per-60-second IP guard. General REST traffic and upload initialization use 300 per minute per user; a lower plan or per-key ceiling can bind first.
Because file paging is offset-based, inserts and deletes during traversal can shift later pages. Pause concurrent mutations for a stable export and deduplicate by file id when that is impossible.
Expected result
Every numeric page is handled at most once for the run, every file id is reconciled, and retryable responses wait for the server’s stated delay while permanent refusals remain actionable.

Related guides
Was this helpful?
Loading helpfulness results…
Voting saves a necessary ballot cookie for up to 180 days so you can change your answer.
Questions and replies
Ask about the steps in this guide. Questions are reviewed before publication.
Keep account details, credentials and private files out of public questions. Use private support for those.
Loading questions…
Sign in to your Dosya account to ask a question.