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

# Outlines API

> Manage document outlines with nested sections

# Outlines API

The Outlines API manages document outlines that structure document content with hierarchical sections.

## Get Outline

Retrieve a complete outline with all sections ordered by index.

```bash theme={null}
GET /api/v1/mrt-outlines/{outline_id}
```

### Path Parameters

| Parameter    | Type   | Required | Description     |
| ------------ | ------ | -------- | --------------- |
| `outline_id` | string | Yes      | UUID of outline |

### Request Example

```bash theme={null}
curl -X GET "https://api.artosai.com/api/v1/mrt-outlines/outline-uuid" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

### Response

```json theme={null}
{
  "outline": {
    "outline_id": "outline-uuid-123",
    "document_metadata": {
      "document_type": "CSR",
      "document_name": "CSR_Final",
      "sponsor_name": "Acme Pharma",
      "study_identifier": "ACME-2024-001"
    },
    "connector_data_id": "project-2024-001",
    "endpoint_analysis": "Initial outline generated from template",
    "rule_type_to_table_like_status": {
      "CopyPasteRule": true
    },
    "sections": [
      {
        "section_id": "1.0",
        "order_index": 0,
        "level": 1,
        "title": "Executive Summary",
        "synopsis": "High-level overview of study findings",
        "template_instructions": "Summarize the key findings in 2-3 paragraphs",
        "template_text": "This section provides a concise overview...",
        "relevant_chunk_ids": ["chunk-uuid-1", "chunk-uuid-2"]
      },
      {
        "section_id": "2.0",
        "order_index": 1,
        "level": 1,
        "title": "Study Design",
        "synopsis": "Description of study methodology",
        "template_instructions": "Describe the study design and primary objectives",
        "template_text": "",
        "relevant_chunk_ids": []
      },
      {
        "section_id": "2.1",
        "order_index": 2,
        "level": 2,
        "title": "Primary Endpoints",
        "synopsis": "Primary efficacy endpoints",
        "template_instructions": "List all primary endpoints with rationale",
        "template_text": "",
        "relevant_chunk_ids": ["chunk-uuid-3"]
      }
    ]
  }
}
```

### Status Codes

* **200 OK**: Outline retrieved successfully
* **400 Bad Request**: Authentication failed or outline not found
* **403 Forbidden**: User not authorized (different organization)
* **500 Internal Server Error**: Database error

***

## Update Outline

Full replacement (PUT) of a document outline. All existing sections are deleted and replaced with the provided structure.

```bash theme={null}
PUT /api/v1/mrt-outlines/{outline_id}
```

### Path Parameters

| Parameter    | Type   | Required | Description     |
| ------------ | ------ | -------- | --------------- |
| `outline_id` | string | Yes      | UUID of outline |

### Request Body

```json theme={null}
{
  "document_metadata": {
    "document_type": "CSR",
    "document_name": "CSR_Final",
    "sponsor_name": "Acme Pharma",
    "study_identifier": "ACME-2024-001"
  },
  "connector_data_id": "project-2024-001",
  "endpoint_analysis": "Updated analysis results",
  "rule_type_to_table_like_status": {
    "CopyPasteRule": true,
    "SummaryRule": false
  },
  "sections": [
    {
      "section_id": "1.0",
      "order_index": 0,
      "level": 1,
      "title": "Executive Summary",
      "synopsis": "Overview of study findings",
      "template_instructions": "Summarize key findings in 2-3 paragraphs",
      "template_text": "This section provides...",
      "relevant_chunk_ids": ["chunk-uuid-1", "chunk-uuid-2"]
    },
    {
      "section_id": "2.0",
      "order_index": 1,
      "level": 1,
      "title": "Study Design",
      "synopsis": "Study methodology description",
      "template_instructions": "Describe the study design and primary objectives",
      "relevant_chunk_ids": []
    }
  ]
}
```

### Request Parameters

| Parameter                        | Type   | Required | Description                                     |
| -------------------------------- | ------ | -------- | ----------------------------------------------- |
| `document_metadata`              | object | Yes      | Outline metadata (must include `document_type`) |
| `sections`                       | array  | Yes      | Section dictionaries (at least one required)    |
| `connector_data_id`              | string | No       | Document set key for search scoping             |
| `endpoint_analysis`              | string | No       | Analysis or processing notes                    |
| `rule_type_to_table_like_status` | object | No       | Map of rule type → boolean for table rendering  |

### Section Parameters

Each section in the `sections` array is a dictionary and can include:

| Parameter               | Type    | Required | Description                                         |
| ----------------------- | ------- | -------- | --------------------------------------------------- |
| `section_id`            | string  | Yes      | Unique section identifier (e.g., `"1.0"`, `"2.1"`)  |
| `order_index`           | integer | Yes      | Position in outline (must be unique)                |
| `level`                 | integer | Yes      | Nesting level (1 = top-level, 2 = subsection, etc.) |
| `title`                 | string  | Yes      | Section title                                       |
| `synopsis`              | string  | No       | Brief section summary                               |
| `template_instructions` | string  | No       | Instructions for generating this section            |
| `template_text`         | string  | No       | Template/boilerplate text                           |
| `relevant_chunk_ids`    | array   | No       | Referenced source chunk IDs                         |

### Request Example

```bash theme={null}
curl -X PUT "https://api.artosai.com/api/v1/mrt-outlines/outline-uuid" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "document_metadata": {
      "document_type": "CSR"
    },
    "sections": [
      {
        "section_id": "section-1",
        "order_index": 0,
        "level": 1,
        "title": "Executive Summary",
        "content": "Updated content"
      }
    ]
  }'
```

### Python Example

```python theme={null}
import requests

url = "https://api.artosai.com/api/v1/mrt-outlines/outline-uuid"
headers = {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json"
}

payload = {
    "document_metadata": {"document_type": "CSR"},
    "sections": [
        {
            "section_id": "section-1",
            "order_index": 0,
            "level": 1,
            "title": "Executive Summary",
            "content": "Updated content"
        }
    ]
}

response = requests.put(url, headers=headers, json=payload)
outline = response.json()
print(f"Updated outline: {outline}")
```

### Response

```json theme={null}
{
  "outline": {
    "outline_id": "outline-uuid-123",
    "document_metadata": {
      "document_type": "CSR",
      "document_name": "CSR_Final",
      "sponsor_name": "Acme Pharma"
    },
    "connector_data_id": "project-2024-001",
    "endpoint_analysis": "Updated analysis results",
    "rule_type_to_table_like_status": {
      "CopyPasteRule": true
    },
    "sections": [
      {
        "section_id": "1.0",
        "order_index": 0,
        "level": 1,
        "title": "Executive Summary",
        "synopsis": "Overview of study findings",
        "template_instructions": "Summarize key findings",
        "template_text": "Updated section content...",
        "relevant_chunk_ids": ["chunk-uuid-1"]
      }
    ]
  }
}
```

### Status Codes

* **200 OK**: Outline updated successfully
* **400 Bad Request**: Invalid outline structure or missing sections
* **401 Unauthorized**: Missing or invalid Bearer token
* **403 Forbidden**: User not authorized
* **404 Not Found**: Outline not found
* **500 Internal Server Error**: Database error

### Important Notes

* **Full Replacement**: This is a PUT operation, not a PATCH. All sections are replaced.
* **Section Order**: `order_index` must be unique across all sections
* **Hierarchical Structure**: Sections support multiple nesting levels via the `level` parameter
* **Cascading Delete**: Old sections and all associated data are deleted before insert
