Skip to content

428 Precondition Required — Meaning, Common Causes & How to Fix

428 4xx Client Error RFC 6585

428 Precondition Required means: The server requires the request to be conditional — it must carry preconditions like If-Match — to prevent lost-update problems. Clients that read-modify-write without concurrency control are told to add the precondition and retry. Client-error 4xx codes mean the request itself is the problem: malformed syntax, missing credentials, forbidden access, a nonexistent resource or a violated precondition. The server is telling the client what to change; retrying the identical request without a fix will reproduce the same error. In practice you will meet 428 when an api enforces optimistic locking and the put lacked if-match; a server protects against lost updates on shared resources; a gateway policy requires conditional headers for write operations. On the client side, gET the resource first, capture its ETag, and resend the write with If-Match; handle 412 by re-reading and merging. On the server side, use 428 to teach clients your concurrency contract; document the required headers and the 412 merge flow.

Advertisement
Ad slot · ref-top

When 428 happens

  • An API enforces optimistic locking and the PUT lacked If-Match
  • A server protects against lost updates on shared resources
  • A gateway policy requires conditional headers for write operations

How to fix it

On the client

GET the resource first, capture its ETag, and resend the write with If-Match; handle 412 by re-reading and merging.

On the server

Use 428 to teach clients your concurrency contract; document the required headers and the 412 merge flow.

Should you retry?

Not retryable as-is: change the request (credentials, payload, URL) first.

Debugging steps

When 428 appears unexpectedly, start by capturing the full exchange: 'curl -i' or the browser DevTools Network tab shows the exact status line and response headers, which often carry the real explanation. Read the error body first — well-designed APIs name the offending field or missing credential. Then diff your actual request, headers included, against the documented contract. For this code specifically, check whether the most common trigger applies to your situation: an api enforces optimistic locking and the put lacked if-match. Compare your exchange against the raw HTTP example above. If you operate the server, correlate the timestamp with application and proxy logs using the request id; if you are the client, verify the request shape against the API documentation before changing anything or retrying.

Notes & gotchas

428 teaches clients your concurrency contract: 'you must send If-Match'. Paired with 412 on stale ETags, it forms a complete optimistic-locking protocol without server-side sessions.

Examples

Raw HTTP
HTTP/1.1 428 Precondition Required
Content-Type: application/json
Content-Length: 117

{
  "error": "precondition_required",
  "message": "An API enforces optimistic locking and the PUT lacked If-Match"
}
curl
curl -i -X PUT -H "Content-Type: application/json" -d @update.json https://api.example.com/v1/resource   # server demands If-Match
JavaScript (fetch)
const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 428) {
  const problem = await res.json(); // read field-level details
  // fix the request (credentials, payload, URL) — identical retries keep failing
  throw new RequestError(problem);
}
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource", timeout=10)
if res.status_code == 428:
    problem = res.json()  # field-level error details
    # correct the request before retrying — identical retries keep failing
    raise RequestProblem(problem)

Frequently asked questions

428 vs 412: what is the difference?

428: you sent no precondition at all and one is required. 412: you sent a precondition and it evaluated to false (resource changed).

Why would an API require If-Match?

To make lost updates impossible: two clients editing the same record cannot silently overwrite each other; the second write fails with 412 and must merge.

Are 4xx errors always the client's fault?

By contract yes — the server asserts the request must change. In practice servers sometimes misuse 4xx for their own problems (e.g. 400 for internal validation bugs), so read the error body before blaming your client code.

Should I retry 4xx responses automatically?

Generally no: the server says the request must change. Exceptions are 408 (fresh connection), 425 (after handshake) and 429 (after Retry-After). Blind retries of 400/401/403/404 just burn quota.

Advertisement
Ad slot · ref-in-article

Try the JSON Validator

Check JSON syntax and locate errors by line and column.

Open tool →