Retries and conflicts
Two things go wrong in any integration that writes to FileSpin, sooner or later:
- A retry does the work twice. Your request reaches FileSpin and succeeds, but the response is lost: a timeout, a dropped connection, a worker restart. Your code retries, and the customer gets two share pages or two copies of the same email.
- A save overwrites someone else's change. Your code reads an asset's metadata, changes one field and writes the record back. If a colleague edited another field in between, your write puts back the old value.
FileSpin has an answer for each: idempotency keys for creates and sends, and revisions for updates. Both are optional, per request. A request without them behaves exactly as it always has.
AI assistants connected through the MCP Server use both automatically.
Idempotency keys: retry without duplicates
Send an Idempotency-Key header with a create or send request. If FileSpin has already completed a request with that key, it returns the first result instead of doing the work again.
curl -X PUT https://app.filespin.io/api/v1/assetshare \
-H "X-FileSpin-Api-Key: $FILESPIN_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-1042-review-share" \
-d '{"file_ids": ["9a1edfb1bb1248a7b263a7d087045c54"], "title": "Order 1042 review"}'
Retry the same request with the same key and you get the same share back, with the response header Idempotent-Replayed: true.
| Endpoint | What a retry would otherwise duplicate |
|---|---|
PUT /api/v1/assetshare | the share page, and the email to its recipients |
POST /api/v1/assetcollection | the collection |
POST /api/v1/notifications/send | the email |
POST /api/v1/ai/schedules | the AI agent schedule |
POST /api/v1/feedback | the report to FileSpin support |
Rules
- The key is yours to choose: 1 to 255 printable ASCII characters, no spaces. Use something tied to the operation, such as an order ID plus an action, or a UUID you store before the first attempt. Keys are scoped to your user, the HTTP method and the path, so the same key on two endpoints never collides.
- The result is kept for 24 hours. Send
Idempotency-Window: <seconds>(60 to 86400) to keep it for less. A shorter window suits keys derived from the request itself, so the same message sent on purpose later still goes out. - Only successful (2xx) results are kept. If the first request failed, retry with the same key and it runs again.
| Situation | Response |
|---|---|
| Same key, same body, first request finished | The first response again, plus Idempotent-Replayed: true |
| Same key while the first request is still running | 409 {"error": "idempotency_in_progress"}: wait a moment and retry with the same key |
| Same key, different body | 422 {"error": "idempotency_key_reused"}: use a new key for a new request |
| Malformed key or window | 400 {"error": "invalid_idempotency_key"} or "invalid_idempotency_window" |
Revisions: save without overwriting
Every record you might read, change and write back carries a revision. Send the revision you read with your write. If the record has changed since, FileSpin refuses the write with 409 and changes nothing, so you can re-read, re-apply your change on top of the current values and try again.
| Record | Read the revision from | Send it as |
|---|---|---|
| Asset metadata | metadata_revision in GET /api/v1/assets/{asset_id}/data | expected_revision (string) on POST /api/v1/assets/{asset_id}/data/update |
| Asset file | versions.live in the same response | expected_version (integer) when replacing the original file |
| Collection | revision in GET /api/v1/assetcollection/{collection_id} | expected_revision (integer) on PATCH / PUT of that collection |
| Share | revision (and updated_at) in GET /api/v1/assetshare/{share_id} | expected_revision (integer) when editing that share |
# 1. Read the metadata and its revision
curl -s https://app.filespin.io/api/v1/assets/$ASSET_ID/data \
-H "X-FileSpin-Api-Key: $FILESPIN_API_KEY"
# ... "data": {"title": "Spring lookbook"}, "metadata_revision": "b061190269b87749" ...
# 2. Write with that revision
curl -s -X POST https://app.filespin.io/api/v1/assets/$ASSET_ID/data/update \
-H "X-FileSpin-Api-Key: $FILESPIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"mode": "REPLACE", "data": {"title": "Spring lookbook 2027"}, "expected_revision": "b061190269b87749"}'
If someone changed the metadata in between, the write returns:
{
"error": "stale_revision",
"message": "The asset's metadata changed since you read it. ...",
"current_revision": "7d2c0a91e4f38b56"
}
A replacement of the original file with an outdated expected_version returns 409 with "code": "stale_version" and current_version.
A successful write returns the new revision (metadata_revision for metadata, revision for collections and shares), so you can make another checked write without reading again.
When to use revisions
- Use them whenever your write is based on something you read: a
REPLACEof the metadata, a collection's asset list you edited locally, share settings a user changed in your own UI. - You don't need them for list changes. Adding or removing values in a list field with
list_ops, and adding or removing assets with a collectionPATCH, are already merged by FileSpin against the current value. - Treat
metadata_revisionas opaque. Compare it for equality only. Collection and share revisions are integers that go up with every edit (a share's views and status changes don't count).
See also
- Response codes
- Rate limits: a
429is refused before any work is done, so retrying it is always safe. - MCP Server: how connected AI assistants use these.