On this page
A 202 Accepted response tells a client that a request was accepted for processing—not that the work succeeded, or even that it will eventually run. For long-running jobs, give the client a stable status URL and define how it should poll, interpret completion, and handle expiration.
Key Takeaways
- Return
202only for acceptance; report the eventual outcome through a separate status resource. - Put the status URL in a documented response field. A
Locationheader can also carry it as an API convention, but clients should not assume every202uses it that way. - Keep the status URL stable throughout the job’s retention period, and define what happens after expiration.
- Authorize every status request, use opaque identifiers, and keep credentials and sensitive input out of URLs.
- Document polling intervals, terminal states, failure details, and retry behavior.
What 202 Accepted means
HTTP 202 Accepted is deliberately noncommittal: processing has not completed and might not ultimately occur. The original HTTP response cannot later turn into a final response, so the client needs another way to learn the outcome. A status resource is a practical API design for that purpose.
A Location header identifies a resource in relation to a response, but its meaning depends on the response context. This article recommends using Location for the status URL as an explicit API contract, not as a universal requirement of 202. Including the URL in the response body makes that contract clear to clients.
Research limitation: RFC 9110 could not be consulted for this draft. Verify its 202 Accepted and Location wording before treating this summary as normative guidance. The message examples below are illustrative; they were not executed.
Advertisement
Design the status resource
Create one status resource per accepted job, such as /v1/jobs/job_7Qx2. The identifier in these examples is deliberately short for readability; use an appropriately unpredictable identifier in a real service.
The following fictional API accepts an export request. statusUrl and pollAfterSeconds are application-defined fields, not standard HTTP fields.
1. Submit the job
POST /v1/exports HTTP/1.1
Host: api.example.test
Authorization: Bearer EXAMPLE_TOKEN
Content-Type: application/json
{"format":"csv"}
The service’s acceptance response could be:
HTTP/1.1 202 Accepted
Location: /v1/jobs/job_7Qx2
Content-Type: application/json
Cache-Control: no-store
{"id":"job_7Qx2","state":"queued","statusUrl":"/v1/jobs/job_7Qx2","pollAfterSeconds":5}
The URL is relative to the API origin, so the client resolves it against the request URL. The service must document that both Location and statusUrl point to the status resource in this response. If it supplies both, they should agree.
Before acknowledging acceptance, persist enough information to recover the job after a process failure. If a database write and queue publication are separate operations, design for failures between them—for example, with a durable outbox. A 202 alone does not guarantee execution; any stronger durability promise belongs in the API contract.
2. Poll the same URL
GET /v1/jobs/job_7Qx2 HTTP/1.1
Host: api.example.test
Authorization: Bearer EXAMPLE_TOKEN
While work is running, the service might return:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{"id":"job_7Qx2","state":"running","pollAfterSeconds":5}
A 200 here means the status request succeeded; it does not mean the job succeeded. Define a small set of states, such as queued, running, succeeded, failed, and, if supported, cancelled. Specify which are terminal. Progress percentages are optional: include them only when their meaning and reliability are clear.
3. Read the completed result
After success, the same status URL can return a terminal representation:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{"id":"job_7Qx2","state":"succeeded","result":{"exportedRecords":42}}
This example returns a small result inline. For larger results, the terminal representation can instead identify a separately authorized result resource. Document its lifetime independently from the status resource’s lifetime. If the status endpoint redirects to a result, document that behavior too; clients should check the destination and authorization policy before following it.
For a failed job, return a terminal failed state with a safe, actionable error code or message. A successful GET of that representation can still be 200: distinguish an error fetching status from a job that finished unsuccessfully. Avoid exposing stack traces, credentials, or internal infrastructure details.
Advertisement
Define expiration and unknown jobs
Publish a retention policy: say when the retention period starts, how long status and results remain available, and whether clients receive an expiry time. Keep the status URL unchanged while the resource is retained.
An API that tracks expired identifiers can distinguish an expired job from an unknown one:
HTTP/1.1 410 Gone
Content-Type: application/json
Cache-Control: no-store
{"error":"job_expired"}
For an identifier it does not recognize, the API might instead return:
HTTP/1.1 404 Not Found
Content-Type: application/json
Cache-Control: no-store
{"error":"job_not_found"}
Distinguishing these cases requires retaining enough information to recognize an expired identifier. If the service deletes all records of it, it may only be able to return 404. It can also deliberately use 404 for inaccessible jobs to reduce information disclosure. Document the chosen behavior, including whether expired results can be recovered or a new job must be submitted.
Polling and retry checklist
- Set a polling policy. Document an initial interval and whether
pollAfterSecondsis a minimum or a suggestion. Clients should stop when they receive a terminal state. - Bound client waiting. Use request timeouts and an overall deadline; a job may remain incomplete longer than the client is willing to wait.
- Handle transient failures. Retry temporary network or service failures with bounded exponential backoff and jitter. Respect applicable server retry guidance and rate limits. Do not treat every failed status request as a failed job.
- Prevent duplicate submissions. A client may lose the
202response and retry the originalPOST. If duplicates matter, define an idempotency-key contract: scope keys to the caller, handle concurrent requests, specify retention, and reject reuse with conflicting input. A key is useful only if the server actually implements the contract. - Plan for abandoned work. Define timeouts, cancellation semantics if offered, and how operators detect jobs stuck in nonterminal states.
Secure the URL and status response
Require authentication where appropriate and authorize each status and result request against the job’s owner or permitted tenant. An opaque, high-entropy job identifier reduces guessability; it is not a substitute for authorization. Decide whether unauthorized callers see 403 or a privacy-preserving 404, and apply that policy consistently.
Do not put bearer tokens, personal data, raw job inputs, or other secrets in the path or query string. URLs can appear in logs, browser history, monitoring systems, and intermediary records. Protect status bodies too: even a state or error message can reveal sensitive business activity. Use HTTPS and consider Cache-Control: no-store for sensitive responses, as in the examples.
If clients receive an absolute status or result URL, document its expected origin. Clients that attach credentials should not send them to an unexpected origin. If a server fetches a supplied URL, parsing it is not sufficient SSRF protection: enforce scheme and destination rules, account for DNS resolution and rebinding, revalidate redirects, and use network egress controls, timeouts, and response-size limits.
Common Mistakes
- Treating
202as success. Acceptance and a terminalsucceededstate are different events. - Using
Locationwithout a contract. Tell clients what the header means for this endpoint and provide a consistent body field. - Returning a new status URL on every poll. A stable resource is easier to store, retry, and support.
- Using job IDs as authorization. Even hard-to-guess URLs can leak.
- Leaving retention undefined. Clients need to know whether a missing job is unknown, expired, or inaccessible.
- Retrying submissions blindly. A lost response can lead to duplicate work unless the API supports and documents idempotency.
Best Practices
Publish the request and response schemas, state transitions, terminal errors, polling policy, authorization rules, and retention window together. Test normal completion, failure, lost submission responses, concurrent duplicate submissions, unauthorized access, and expiry. Monitor queue delays and stuck jobs without logging secrets.
Conclusion
A useful 202 Accepted design makes the asynchronous contract explicit: return a stable status URL, protect it like any other resource, and tell clients how to poll until completion or expiration.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.