> ## 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.

# Add CRDT Data

Use this API to create new CRDT editor data on the backend. Use it with the [Multiplayer Editing (Yjs)](/realtime-collaboration/crdt/setup/core) feature.

# Endpoint

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

# 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 CRDT content to store. 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": "Hello, collaborative world!",
    "type": "text"
  }
}
```

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

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

**Array:**

```JSON theme={null}
{
  "data": {
    "organizationId": "YOUR_ORGANIZATION_ID",
    "documentId": "YOUR_DOCUMENT_ID",
    "editorId": "my-list-editor",
    "data": [{ "id": "1", "text": "Item 1" }, { "id": "2", "text": "Item 2" }],
    "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>Hello World</paragraph>",
    "type": "xml",
    "contentKey": "default"
  }
}
```

# Response

## Success Response

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

## Error Responses

**CRDT data already exists for the given editor ID:**

```JSON theme={null}
{
  "error": {
    "message": "CRDT data already exists for this editor ID.",
    "status": "ALREADY_EXISTS"
  }
}
```

**Invalid arguments:**

```JSON theme={null}
{
  "error": {
    "message": "Editor ID is required.",
    "status": "INVALID_ARGUMENT"
  }
}
```

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