> ## Documentation Index
> Fetch the complete documentation index at: https://velt.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Update CRDT Data

Use this API to replace existing CRDT editor data on the backend. The update creates proper CRDT operations on the existing document state so connected clients can pick up the change. Use it with the [Multiplayer Editing (Yjs)](/realtime-collaboration/crdt/setup/core) feature.

# Endpoint

`POST https://api.velt.dev/v2/crdt/update`

# Headers

<ParamField header="x-velt-api-key" type="string" required>
  Your API key.
</ParamField>

<ParamField header="x-velt-auth-token" type="string" required>
  Your [Auth Token](/security/auth-tokens).
</ParamField>

# Body Parameters

<ParamField body="data" type="object" required>
  <Expandable title="properties">
    <ParamField body="organizationId" type="string" required>
      Organization ID where the document belongs
    </ParamField>

    <ParamField body="documentId" type="string" required>
      Document ID containing the CRDT editor data
    </ParamField>

    <ParamField body="editorId" type="string" required>
      Unique identifier for the specific CRDT editor instance
    </ParamField>

    <ParamField body="data" type="string | object | array" required>
      The new CRDT content to replace existing data with. Must match the specified `type`: string for `text`/`xml`, object for `map`, array for `array`.
    </ParamField>

    <ParamField body="type" type="string" required>
      The CRDT data type. One of: `text`, `map`, `array`, `xml`.
    </ParamField>

    <ParamField body="contentKey" type="string">
      Yjs content key name. Defaults to `content`. Use `default` for TipTap.
    </ParamField>
  </Expandable>
</ParamField>

## Example Requests

**Text (e.g., CodeMirror):**

```JSON theme={null}
{
  "data": {
    "organizationId": "YOUR_ORGANIZATION_ID",
    "documentId": "YOUR_DOCUMENT_ID",
    "editorId": "my-collab-note",
    "data": "Updated collaborative content!",
    "type": "text"
  }
}
```

**Map (e.g., ReactFlow):**

```JSON theme={null}
{
  "data": {
    "organizationId": "YOUR_ORGANIZATION_ID",
    "documentId": "YOUR_DOCUMENT_ID",
    "editorId": "my-flow-editor",
    "data": { "nodes": { "node-1": { "label": "Updated" } }, "edges": {} },
    "type": "map"
  }
}
```

**Array:**

```JSON theme={null}
{
  "data": {
    "organizationId": "YOUR_ORGANIZATION_ID",
    "documentId": "YOUR_DOCUMENT_ID",
    "editorId": "my-list-editor",
    "data": [{ "id": "1", "text": "Updated Item 1" }, { "id": "3", "text": "New Item 3" }],
    "type": "array"
  }
}
```

**XML (e.g., TipTap):**

```JSON theme={null}
{
  "data": {
    "organizationId": "YOUR_ORGANIZATION_ID",
    "documentId": "YOUR_DOCUMENT_ID",
    "editorId": "my-rich-text-editor",
    "data": "<paragraph>Updated content</paragraph><heading level=\"2\">New heading</heading>",
    "type": "xml",
    "contentKey": "default"
  }
}
```

# Response

## Success Response

```JSON theme={null}
{
  "result": {
    "status": "success",
    "message": "CRDT data updated successfully."
  }
}
```

## Error Responses

**No CRDT data found for the given editor ID:**

```JSON theme={null}
{
  "error": {
    "message": "No CRDT data found for this editor ID.",
    "status": "NOT_FOUND"
  }
}
```

**Invalid arguments:**

```JSON theme={null}
{
  "error": {
    "message": "Data must be a string for type text.",
    "status": "INVALID_ARGUMENT"
  }
}
```

<ResponseExample>
  ```json theme={null}
  {
    "result": {
      "status": "success",
      "message": "CRDT data updated successfully."
    }
  }
  ```
</ResponseExample>
