Writes, idempotency and errors
Apply atomic changes, retry safely and respond to Pigeon API errors.
On this page
Submit an operation
Send a batch of mutations to POST /v1/operations with an Idempotency-Key header. For a creation, generate a durable UUID and pass it as ref.new. For a strict edit to a record your client created, use ref.id and the revision and revision_op you edited in base. Operations request and response schemas
To create a workout, use a token with workout:write. Generate two UUIDs and set PIGEON_OPERATION_KEY and PIGEON_CREATE_ID before sending. Save both values if you might need to retry.
curl --fail-with-body \
--header "Authorization: Bearer $PIGEON_ACCESS_TOKEN" \
--header "Idempotency-Key: $PIGEON_OPERATION_KEY" \
--header "Content-Type: application/json" \
--data @- https://api.sendtopigeon.com/v1/operations <<EOF
{
"mutations": [{
"action": "upsert",
"ref": {"new": "$PIGEON_CREATE_ID"},
"kind": "workout",
"schema": "[email protected]",
"body": {
"id": "\$root",
"type": "workout",
"fields": {
"title": "Quickstart workout",
"equipment": [],
"target_muscles": [],
"contraindications": []
},
"lists": {"blocks": []}
}
}]
}
EOFUse the receipt to learn each mutation's outcome and pull the change feed to apply the resulting records in order. When you use a merge policy, Pigeon can merge compatible changes and preserve an edit as a conflict copy when the final record would violate a rule.
Retry the same intent safely
Persist the key and the serialized request before sending. If you lose the response, retry the same bytes with the same key and create IDs. Use a new key for a changed intent. After a strict edit fails with revision_conflict or base_unknown, refresh the mirror and inspect the current record before deciding what to submit.
Handle a problem response
Hub write errors use application/problem+json. Branch on code and keep the request-id response header for troubleshooting.
| Status and code | Action |
|---|---|
401 unauthorized | Refresh an expired OAuth token or replace an expired personal access token. |
401 episode_superseded or 403 connection_disconnected | Stop jobs for the old grant. Authorize again if the user wants to reconnect. |
403 scope_denied | Check the requested action, granted scopes and record link. |
403 connection_paused | Wait until the connection is active. |
409 revision_conflict or base_unknown | Pull the current record and reconcile the rejected edit. |
422 idempotency_key_reused | The key was already used for another payload. Reuse the original payload for a retry or issue a new key for a new intent. |
422 invalid_operation, invalid_mutation or body_invalid | Check the request against the API reference and the record schemas. |
429 rate_limited or snapshot_rate_limited | Honor Retry-After before making another request. |
503 internal_error | Back off and honor Retry-After if supplied. Retry an uncertain write with its original key and payload. |