ETags & conditional writes
Read, get an ETag, write with If-Match — and never overwrite someone else's change.
When two writers race on the same resource, the slower one silently
destroys the faster one's work — unless the write is conditional. Resources
with optimistic concurrency return a strong ETag on reads; send it back in
If-Match when you write:
GET /v1/outbound-policy
Authorization: Bearer kejue_<prefix>_<secret>
HTTP/1.1 200 OK
ETag: "outbound-policy-p4-o9"PUT /v1/outbound-policy
Authorization: Bearer kejue_<prefix>_<secret>
Content-Type: application/json
If-Match: "outbound-policy-p4-o9"If someone changed the resource since your read, you get 412 precondition_failed — with the current ETag in the response. Re-read,
merge your intent against the fresh state, and retry with the new tag. Never
auto-resend the stale body.
{
"error": {
"code": "precondition_failed",
"message": "resource changed since the supplied ETag was issued",
"request_id": "..."
}
}Use the exact quoted strong ETag returned by the resource. Weak cache
validators (W/"…") are not valid for If-Match; re-read the resource rather
than stripping the weak prefix or dropping the condition.
Practical notes
If-Match: *means "apply regardless of version" — fine for explicitly idempotent cleanup, useless for read-modify-write safety. Prefer exact tags.- No-ops are cheap. Submitting an unchanged desired state succeeds, preserves the version and ETag, and still writes its audit trail — so declarative reconciliation loops don't manufacture churn.
- ETags are representation versions, not row counters. One tag can cover nested state (a board's tag changes when its insights reorder; the outbound policy tag folds in the organization timezone). Treat them as opaque.
- Virtual defaults exist. Some config reads return a complete default
(e.g. after-call config with
version: 0) before anything is persisted — including an ETag valid for the first conditionalPATCH. A null resource ID is not a missing endpoint. - Only where declared. Send
If-Matchwhere the operation lists the parameter — common on config/catalog objects, boards, contacts, telephony provisioning, and transfer cancellation.
Idempotency-Key and If-Match solve different races:
idempotency dedupes network retries of one POST;
If-Match rejects a write based on an obsolete read. Some POST actions
(transfer cancellation, secret rotation) take both.