What 412 Precondition Failed means

412 Precondition Failed is the response when an If-Match, If-None-Match, If-Unmodified-Since, or other conditional header does not match the resource's current state. The most common case: optimistic concurrency control. The client GETs a resource with ETag "v1", modifies it, and sends PUT with If-Match: "v1". If another client updated the resource in between (current ETag is "v2"), the server returns 412 instead of overwriting.

When servers should return it: Return 412 when a request includes an If-Match or If-Unmodified-Since header and the precondition does not match. This protects against lost updates.

Common causes

  • ETag in If-Match header does not match current ETag
  • If-Unmodified-Since timestamp is older than the resource's last modification
  • Concurrent update happened between GET and PUT

How to fix 412 Precondition Failed

  • GET the resource again to get the current ETag
  • Apply your changes to the latest version
  • Retry the PUT with the new If-Match value
  • For repeated 412s, implement merge logic or prompt the user

Example response

curl -i -X PUT -H 'If-Match: "v1"' \
  -d '{"name":"Ada"}' https://api.example.com/users/42

HTTP/2 412
etag: "v3"
content-type: application/json
{"error":"precondition failed","current_etag":"v3"}

More references

For a one-page reference of all HTTP status codes, see the HTTP cheat sheet. For testing API responses, try the API Tester tool. For inspecting responses on the command line, the curl cheat sheet covers the most common flags.