Arke
BuildEntities

Update Entities

How to update entities using Compare-And-Swap (CAS) for safe concurrent updates.

Basic Update

PUT /entities/:id
Content-Type: application/json
Authorization: Bearer <token>

{
  "expected_cid": "bafyreig...",
  "properties_merge": {
    "description": "Updated description"
  }
}

CAS Requirement

The expected_cid field is required. It must match the entity's current tip CID. If another update occurred since you last read the entity, you'll get a 409 Conflict error.

Recovery pattern:

  1. Fetch the entity again to get the new CID
  2. Reapply your changes
  3. Retry the update with the new CID

Update Fields

FieldDescription
expected_cidRequired. Current tip CID for CAS guard.
properties_mergeMerge into existing properties (shallow merge)
properties_replaceReplace all properties entirely
relationships_addAdd new relationships
relationships_removeRemove relationships by predicate + peer
noteVersion note for this update

Adding Relationships

{
  "expected_cid": "bafyreig...",
  "relationships_add": [
    {
      "predicate": "references",
      "peer": "01JOTHER..."
    }
  ]
}

Removing Relationships

{
  "expected_cid": "bafyreig...",
  "relationships_remove": [
    {
      "predicate": "references",
      "peer": "01JOTHER..."
    }
  ]
}

Conflict Resolution

When you receive a 409 Conflict:

{
  "error": "CAS conflict",
  "expected": "bafyreig...",
  "actual": "bafyreih...",
  "status": 409
}

The actual field contains the current tip CID. Fetch the latest version, merge your changes, and retry.

On this page