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

Use this API to add documents with metadata to an organization.

# Endpoint

`POST https://api.velt.dev/v2/organizations/documents/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](/docs/security/auth-tokens).
</ParamField>

# Body

#### Params

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

    <ParamField body="createOrganization" type="boolean">
      If set to true, a new organization will be created (if it doesn't exist) before the document(s) are created.
    </ParamField>

    <ParamField body="documents" type="Document[]" required>
      Array of Document objects
    </ParamField>

    <ParamField body="folderId" type="string">
      Folder ID to add the documents to.
    </ParamField>

    <ParamField body="createFolder" type="boolean">
      If set to true and `folderId` is provided but doesn't exist, a new folder will be created before the document(s) are created.
    </ParamField>
  </Expandable>
</ParamField>

## **Example Requests**

#### 1. Create new documents

```JSON theme={null}
{
  "data": {
    "organizationId": "yourOrganizationId",
    "documents": [
      {
        "documentId": "yourDocumentId",
        "documentName": "Your Document Name"
      }
    ]
  }
}
```

#### 2. Create new documents in a specific folder

```JSON theme={null}
{
  "data": {
    "organizationId": "yourOrganizationId",
    "documents": [
      {
        "documentId": "yourDocumentId",
        "documentName": "Your Document Name"
      }
    ],
    "folderId": "yourFolderId"
  }
}
```

# Response

#### Success Response

```JSON theme={null}
{
  "result": {
    "status": "success",
    "message": "Document(s) added successfully.",
    "data": {
      "yourDocumentId": {
        "success": true,
        "id": "8121657101517513",
        "message": "Added Successfully"
      }
    }
  }
}
```

#### Failure Response

```JSON theme={null}
{
  "error": {
    "message": "ERROR_MESSAGE",
    "status": "INVALID_ARGUMENT"
  }
}
```

#### Partial Failures

When only some of the documents in the batch fail, this endpoint returns HTTP `500` and puts a per-item breakdown in `error.details`, keyed by the document IDs you sent.

<Warning>
  A partial failure is reported as `500 INTERNAL` even when nothing actually went wrong on the server, such as when a document simply does not exist. Branch on the per-item `code` rather than the HTTP status when deciding whether to retry. Retrying on the status alone will loop on `already-exists`, which will never succeed.
</Warning>

<ResponseField name="code" type="string">
  Why this particular item failed. Present on every entry with `"success": false`.

  | Value            | Meaning                                 | Safe to retry? |
  | ---------------- | --------------------------------------- | -------------- |
  | `already-exists` | A document with this ID already exists. | No             |
  | `internal`       | A genuine server-side failure.          | Yes            |
</ResponseField>

```JSON theme={null}
{
  "error": {
    "status": "INTERNAL",
    "message": "Error adding document(s).",
    "details": {
      "yourDocumentId1": {
        "success": true,
        "id": "8121657101517513",
        "message": "Added Successfully"
      },
      "yourDocumentId2": {
        "success": false,
        "id": "yourDocumentId2",
        "message": "Document already exists",
        "code": "already-exists"
      }
    }
  }
}
```

<ResponseExample>
  ```js theme={null}
  {
    "result": {
      "status": "success",
      "message": "Document(s) added successfully.",
      "data": {
        "yourDocumentId": {
          "success": true,
          "id": "8121657101517513",
          "message": "Added Successfully"
        }
      }
    }
  }
  ```
</ResponseExample>
