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

# Attach Existing Documents

> Attach existing workspace documents to an extraction session.

Use this endpoint when documents already exist at workspace scope and you only want to link them to a session.

## Request

```http theme={null}
POST /extractions/sessions/770e8400-e29b-41d4-a716-446655440000/documents/attach HTTP/1.1
Host: api.raydocs.com
Authorization: Bearer <token>
Content-Type: application/json

{
  "document_ids": [
    "880e8400-e29b-41d4-a716-446655440000"
  ]
}
```

### Body Parameters

| Parameter      | Type         | Required | Description                      |
| -------------- | ------------ | -------- | -------------------------------- |
| `document_ids` | array\[uuid] | Yes      | Workspace document IDs to attach |

## Response

`200 OK` when attachment succeeds.

```json theme={null}
{
  "data": [
    {
      "id": "880e8400-e29b-41d4-a716-446655440000",
      "workspace_id": "660e8400-e29b-41d4-a716-446655440000",
      "filename": "invoice.pdf",
      "status": "processed"
    }
  ]
}
```

`422 Unprocessable Entity` if one or more documents do not belong to the session workspace.


## OpenAPI

````yaml post /extractions/sessions/{sessionId}/documents/attach
openapi: 3.0.1
info:
  title: Raydocs API
  description: REST API for document extraction with AI-powered data parsing
  version: 1.0.0
servers:
  - url: https://api.raydocs.com
security:
  - bearerAuth: []
tags:
  - name: Workspaces
    description: Create and manage workspaces.
  - name: Workspace Users
    description: Manage users within a workspace.
  - name: Extraction Templates
    description: Define extraction schemas and settings.
  - name: Extraction Sessions
    description: Manage extraction jobs and documents.
  - name: Batch Operations
    description: Bulk operations on sessions.
  - name: Documents
    description: Upload and manage source documents.
  - name: Results
    description: Access extraction results.
paths:
  /extractions/sessions/{sessionId}/documents/attach:
    post:
      tags:
        - Extraction Sessions
      summary: Attach Existing Session Documents
      description: >-
        Attach existing workspace documents to a session. Requires
        `sessions-write`.
      operationId: attachSessionDocuments
      parameters:
        - name: sessionId
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - document_ids
              properties:
                document_ids:
                  type: array
                  description: Existing workspace document ids to attach
                  items:
                    type: string
                    format: uuid
      responses:
        '200':
          description: Documents attached
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/Document'
        '403':
          description: Forbidden
        '422':
          description: Validation error
components:
  schemas:
    Document:
      type: object
      properties:
        id:
          type: string
          format: uuid
          readOnly: true
        workspace_id:
          type: integer
        filename:
          type: string
        mime:
          type: string
        size:
          type: integer
          description: File size in bytes
        sha256:
          type: string
          minLength: 64
          maxLength: 64
        status:
          type: string
          enum:
            - uploaded
            - queued
            - parsing
            - parsed
            - processed
            - failed
        source_type:
          type: string
          enum:
            - upload
            - url
            - connector
        source_url:
          type: string
          nullable: true
        parsings:
          type: array
          items:
            $ref: '#/components/schemas/DocumentParsingSummary'
        created_at:
          type: string
          format: date-time
          readOnly: true
    DocumentParsingSummary:
      type: object
      properties:
        id:
          type: string
          format: uuid
        config_hash:
          type: string
        status:
          type: string
          enum:
            - queued
            - processing
            - ready
            - failed
        parser_version:
          type: string
        updated_at:
          type: string
          format: date-time
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Personal Access Token created from the Raydocs dashboard.

        Include in the Authorization header: `Bearer <your_token>`

        See [API Keys](/api-reference/api-keys) for token creation and
        management.

````