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

# Templates

> Template CRUD and marketplace endpoints

# Templates API

## List Templates

```http theme={null}
GET /api/templates
```

List templates available to the current user (public + organization + personal).

**Query Parameters:**

| Parameter  | Type   | Description                |
| ---------- | ------ | -------------------------- |
| `category` | string | Filter by category         |
| `search`   | string | Search by name/description |
| `type`     | string | Filter by template type    |

<CodeGroup>
  ```bash curl theme={null}
  curl -G https://app.thig.ai/api/templates \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -d "category=product" \
    -d "search=mobile"
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/templates?category=product&search=mobile', {
    headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
  });
  const data = await res.json();
  ```
</CodeGroup>

## Get Template

```http theme={null}
GET /api/templates/{id}
```

Returns template details. `systemPrompt` is replaced with `[Protected]` for non-superadmin users on system/marketplace templates.

<CodeGroup>
  ```bash curl theme={null}
  curl https://app.thig.ai/api/templates/tmpl_456 \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/templates/tmpl_456', {
    headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
  });
  const template = await res.json();
  ```
</CodeGroup>

## Template Versions

```http theme={null}
GET /api/templates/{id}/versions
```

List all versions of a template. Requires org admin.

## Restore Template Version

```http theme={null}
POST /api/templates/{id}/restore
```

**Body:** `{ "versionId": "ver_123" }`

***

## Admin Template Management

### List (Admin)

```http theme={null}
GET /api/admin/templates
```

**Query Parameters:**

| Parameter      | Type    | Description                                 |
| -------------- | ------- | ------------------------------------------- |
| `templateType` | string  | personal, organization, system, marketplace |
| `category`     | string  | Template category                           |
| `visibility`   | string  | personal, organization, public              |
| `isActive`     | boolean | Active status                               |
| `isFeatured`   | boolean | Featured status                             |
| `pricingTier`  | string  | Pricing tier filter                         |
| `search`       | string  | Search query                                |
| `sortBy`       | string  | Sort field                                  |
| `sortOrder`    | string  | asc or desc                                 |
| `limit`        | number  | Results per page                            |
| `offset`       | number  | Pagination offset                           |

### Create Template

```http theme={null}
POST /api/admin/templates
```

**Body:**

| Field             | Type      | Required | Description                                 |
| ----------------- | --------- | -------- | ------------------------------------------- |
| `name`            | string    | Yes      | Template name                               |
| `description`     | string    | Yes      | Description                                 |
| `category`        | string    | Yes      | Category                                    |
| `templateType`    | string    | No       | personal, organization, system, marketplace |
| `systemPrompt`    | string    | No       | AI instructions                             |
| `initialQuestion` | string    | No       | First question AI asks                      |
| `sections`        | string\[] | No       | PRD sections                                |
| `tags`            | string\[] | No       | Tags                                        |
| `features`        | string\[] | No       | Key features                                |
| `visibility`      | string    | No       | personal, organization, public              |
| `isActive`        | boolean   | No       | Active status                               |
| `isFeatured`      | boolean   | No       | Featured status                             |
| `pricingTier`     | string    | No       | Pricing tier                                |

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://app.thig.ai/api/admin/templates \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "SaaS PRD Template",
      "description": "Optimized for SaaS product requirements",
      "category": "product",
      "sections": ["Problem Statement", "User Personas", "Features", "Success Metrics"],
      "tags": ["saas", "product"],
      "visibility": "organization"
    }'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/admin/templates', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: 'SaaS PRD Template',
      description: 'Optimized for SaaS product requirements',
      category: 'product',
      sections: ['Problem Statement', 'User Personas', 'Features', 'Success Metrics'],
      tags: ['saas', 'product'],
      visibility: 'organization'
    })
  });
  const template = await res.json();
  ```
</CodeGroup>

### Update Template

```http theme={null}
PATCH /api/admin/templates/{id}
```

Partial update. System/marketplace templates blocked for non-superadmins.

### Delete Template

```http theme={null}
DELETE /api/admin/templates/{id}
```

***

## Marketplace

### Browse Marketplace

```http theme={null}
GET /api/marketplace-templates
```

Public endpoint. No authentication required.

**Query Parameters:**

| Parameter     | Type    | Description        |
| ------------- | ------- | ------------------ |
| `category`    | string  | Filter by category |
| `search`      | string  | Search query       |
| `featured`    | boolean | Featured only      |
| `pricingTier` | string  | Tier filter        |
| `sort`        | string  | Sort order         |

<CodeGroup>
  ```bash curl theme={null}
  curl -G https://app.thig.ai/api/marketplace-templates \
    -d "category=product" \
    -d "featured=true"
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/marketplace-templates?category=product&featured=true');
  const data = await res.json();
  ```
</CodeGroup>

### Get Marketplace Template

```http theme={null}
GET /api/marketplace-templates/{templateId}
```

### Submit Template

```http theme={null}
POST /api/template-submissions
```

Submit a community template for marketplace approval.

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://app.thig.ai/api/template-submissions \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"templateId": "tmpl_789"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/template-submissions', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ templateId: 'tmpl_789' })
  });
  const submission = await res.json();
  ```
</CodeGroup>

### List My Submissions

```http theme={null}
GET /api/template-submissions
```

View your own template submissions and their approval status.
