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

# Organization

> Organization settings, members, branding, domain, and billing endpoints

# Organization API

## Settings

### Get Settings

```http theme={null}
GET /api/organization/settings
```

Returns organization name, branding, notification preferences, and plan details.

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

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

### Update Settings

```http theme={null}
PATCH /api/organization/settings
```

Requires Admin or Owner role.

<CodeGroup>
  ```bash curl theme={null}
  curl -X PATCH https://app.thig.ai/api/organization/settings \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"name": "Acme Corp", "settings": {"notifications": {"emailDigest": true}}}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/organization/settings', {
    method: 'PATCH',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: 'Acme Corp',
      settings: { notifications: { emailDigest: true } }
    })
  });
  const data = await res.json();
  ```
</CodeGroup>

***

## Members

### List Members

```http theme={null}
GET /api/organization/members
```

Returns all org members with roles and user data.

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

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

### Update Member Role

```http theme={null}
PATCH /api/organization/members/{memberId}
```

Requires Admin or Owner role.

**Body:**

```json theme={null}
{ "role": "admin" }
```

Allowed values: `admin`, `member`, `viewer`.

<CodeGroup>
  ```bash curl theme={null}
  curl -X PATCH https://app.thig.ai/api/organization/members/mem_456 \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"role": "admin"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/organization/members/mem_456', {
    method: 'PATCH',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ role: 'admin' })
  });
  const data = await res.json();
  ```
</CodeGroup>

### Remove Member

```http theme={null}
DELETE /api/organization/members/{memberId}
```

***

## Invitations

### List Invitations

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

Requires Admin or Owner. Returns all pending invitations.

### Send Invitation

```http theme={null}
POST /api/invitations
```

**Body:**

| Field     | Type   | Required | Description                    |
| --------- | ------ | -------- | ------------------------------ |
| `email`   | string | Yes      | Invitee email                  |
| `role`    | string | Yes      | `admin`, `member`, or `viewer` |
| `message` | string | No       | Personal message               |

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://app.thig.ai/api/invitations \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"email": "jane@example.com", "role": "member", "message": "Join our PRD team!"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/invitations', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      email: 'jane@example.com',
      role: 'member',
      message: 'Join our PRD team!'
    })
  });
  const invitation = await res.json();
  ```
</CodeGroup>

### Verify Invitation

```http theme={null}
GET /api/invitations/verify?token=INVITATION_TOKEN
```

Public. Check if an invitation token is valid.

### Accept Invitation

```http theme={null}
POST /api/invitations/accept
```

**Body:** `{ "token": "INVITATION_TOKEN" }`

### Resend Invitation

```http theme={null}
POST /api/invitations/{invitationId}
```

### Cancel Invitation

```http theme={null}
DELETE /api/invitations/{invitationId}
```

***

## Branding

### Update Branding

```http theme={null}
POST /api/organization/branding
```

**Body:**

| Field          | Type   | Description                 |
| -------------- | ------ | --------------------------- |
| `primaryColor` | string | Hex color (e.g., "#10B981") |
| `logo`         | string | Logo URL or base64          |
| `companyName`  | string | Company name                |

### Upload Logo

```http theme={null}
POST /api/organization/branding/logo
```

Send as `multipart/form-data` with `file` field. Max 2MB, images only.

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://app.thig.ai/api/organization/branding/logo \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -F "file=@./logo.png"
  ```

  ```javascript JavaScript theme={null}
  const formData = new FormData();
  formData.append('file', logoFileInput.files[0]);

  const res = await fetch('https://app.thig.ai/api/organization/branding/logo', {
    method: 'POST',
    headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
    body: formData
  });
  const { logoUrl } = await res.json();
  ```
</CodeGroup>

**Response:**

```json theme={null}
{ "logoUrl": "https://storage.supabase.co/..." }
```

***

## Custom Domain

### Set Domain

```http theme={null}
POST /api/organization/domain
```

**Body:** `{ "domain": "prd.yourcompany.com" }`

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://app.thig.ai/api/organization/domain \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"domain": "prd.yourcompany.com"}'
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch('https://app.thig.ai/api/organization/domain', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ domain: 'prd.yourcompany.com' })
  });
  const data = await res.json();
  ```
</CodeGroup>

### Verify Domain

```http theme={null}
POST /api/organization/domain/verify
```

Checks CNAME and TXT DNS records. Rate-limited.

**Response:**

```json theme={null}
{
  "verified": true,
  "checks": { "cname": true, "txt": true },
  "message": "Domain verified successfully"
}
```

***

## Billing

### Get Billing Info

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

Returns plan details, usage per resource, billing history, and usage trends.

### Create Checkout

```http theme={null}
POST /api/billing/checkout
```

**Body:**

| Field      | Type   | Required | Description           |
| ---------- | ------ | -------- | --------------------- |
| `planId`   | string | Yes      | Plan to subscribe to  |
| `interval` | string | Yes      | `monthly` or `annual` |

**Response:**

```json theme={null}
{ "checkout_url": "https://checkout.dodopayments.com/..." }
```

### Billing Portal

```http theme={null}
POST /api/billing/portal
```

**Response:**

```json theme={null}
{ "link": "https://portal.dodopayments.com/..." }
```

***

## Admin Endpoints

### Dashboard Stats

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

Returns project counts, status breakdown, recent projects, user stats, and activity timeline.

### List Org Projects (Admin)

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

Full filtering support — search, status, template, priority, date range, assignee, sort.

### Usage Analytics

```http theme={null}
GET /api/admin/analytics/usage
```

**Query Parameters:**

| Parameter         | Type    | Description                 |
| ----------------- | ------- | --------------------------- |
| `userId`          | string  | Filter by user              |
| `projectId`       | string  | Filter by project           |
| `days`            | number  | Lookback period (7, 30, 90) |
| `templateMetrics` | boolean | Include template stats      |
| `alerts`          | boolean | Include usage alerts        |

### Delete All Projects

```http theme={null}
POST /api/admin/settings/delete-all-projects
```

Irreversible. Requires Admin or Owner.

### Delete Organization

```http theme={null}
POST /api/admin/settings/delete-organization
```

Irreversible. Requires Owner.
