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

# Create Document Record

> Register a new document record in the workspace's document library

## Request

Binary uploads are handled out-of-band through a signed URL flow. This endpoint records the metadata for a document whose bytes have already been uploaded to the workspace's object store at `storage_path`. To obtain a signed upload URL, use `POST /v1/documents/upload-url` (documented separately under Storage).

### Headers

```
Authorization: Bearer wbk_your_api_key_here
Content-Type: application/json
```

<ParamField header="Idempotency-Key" type="string">
  Optional UUID for retry deduplication within 24 hours.
</ParamField>

### Body Parameters

<ParamField body="name" type="string" required>
  Display name of the document. 1 - 255 characters.
</ParamField>

<ParamField body="mime_type" type="string" required>
  IANA media type of the file (e.g. `application/pdf`, `image/png`).
</ParamField>

<ParamField body="storage_path" type="string" required>
  Object storage key where the uploaded bytes live. Usually returned by the signed-upload flow.
</ParamField>

<ParamField body="size_bytes" type="integer">
  Size of the uploaded file, in bytes. Used for quota tracking.
</ParamField>

<ParamField body="description" type="string">
  Optional description.
</ParamField>

<ParamField body="folder" type="string">
  Optional folder path. Created on demand. Example: `/clients/acme/ndas`.
</ParamField>

<ParamField body="tags" type="array">
  Optional array of tag strings.
</ParamField>

## Response

<ResponseField name="data" type="object">
  The created document record (same shape as `GET /v1/documents/{id}`).
</ResponseField>

Responses include `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`, and `X-Request-ID`.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    https://data.leadlex.com/functions/v1/api-gateway/v1/documents \
    -H "Authorization: Bearer wbk_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Acme-NDA-2026.pdf",
      "mime_type": "application/pdf",
      "storage_path": "workspaces/ws_123/documents/new-upload.pdf",
      "size_bytes": 183204,
      "folder": "/clients/acme/ndas",
      "tags": ["nda", "confidentiality"]
    }'
  ```

  ```python Python theme={null}
  import requests

  API_KEY = "wbk_your_api_key_here"
  BASE_URL = "https://data.leadlex.com/functions/v1/api-gateway"

  payload = {
      "name": "Acme-NDA-2026.pdf",
      "mime_type": "application/pdf",
      "storage_path": "workspaces/ws_123/documents/new-upload.pdf",
      "size_bytes": 183204,
      "folder": "/clients/acme/ndas",
      "tags": ["nda", "confidentiality"],
  }
  r = requests.post(
      f"{BASE_URL}/v1/documents",
      headers={
          "Authorization": f"Bearer {API_KEY}",
          "Content-Type": "application/json",
      },
      json=payload,
  )
  print(r.json()["data"]["id"])
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch(
    'https://data.leadlex.com/functions/v1/api-gateway/v1/documents',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer wbk_your_api_key_here',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        name: 'Acme-NDA-2026.pdf',
        mime_type: 'application/pdf',
        storage_path: 'workspaces/ws_123/documents/new-upload.pdf',
        size_bytes: 183204,
        folder: '/clients/acme/ndas',
        tags: ['nda'],
      }),
    }
  );
  const { data } = await res.json();
  console.log(data.id);
  ```
</CodeGroup>

### Example Response

```json theme={null}
{
  "data": {
    "id": "doc_01HY1",
    "name": "Acme-NDA-2026.pdf",
    "description": null,
    "mime_type": "application/pdf",
    "size_bytes": 183204,
    "storage_path": "workspaces/ws_123/documents/new-upload.pdf",
    "folder": "/clients/acme/ndas",
    "tags": ["nda", "confidentiality"],
    "created_by": "usr_01HW0",
    "created_at": "2026-04-17T10:45:00Z",
    "updated_at": "2026-04-17T10:45:00Z"
  }
}
```

## Errors

| Status | Code                       | Description                                              |
| ------ | -------------------------- | -------------------------------------------------------- |
| 400    | `validation_error`         | Missing required fields or invalid MIME type             |
| 401    | `invalid_key`              | Invalid or expired API key                               |
| 403    | `insufficient_permissions` | Missing `write:documents` permission                     |
| 409    | `storage_conflict`         | A document already exists at the supplied `storage_path` |
| 429    | `rate_limited`             | Rate limit exceeded                                      |
