---
title: "Organizations & Workspaces API"
description: "Endpoints to query active organization metadata, manage collaborators, and inspect workspace quotas."
---

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

# Organizations & Workspaces API

# Organizations & Workspaces API

The Organizations API allows programmatic inspection of workspace metadata, subscription limits, usage telemetry, and team member access control with role-based permissions (RBAC).

---

## 1. Retrieve Current Workspace

Inspect the active workspace associated with the authenticated API key or session token.

**GET** `/api/v1/organizations/current`

### Request Headers

```http
Authorization: Bearer <token>
Accept: application/json
```

### Response Example (HTTP 200 OK)

```json
{
  "code": 0,
  "data": {
    "id": "org_91c4a02f",
    "name": "Acme Growth Team",
    "slug": "acme-growth",
    "logo": "https://cdn.brand.com/logo.png",
    "plan": "pro",
    "allowedDomains": ["brand.com", "link.brand.com"],
    "linkCount": 1420,
    "linkQuota": 25000,
    "clickCountMonthly": 84120,
    "clickQuotaMonthly": 2500000,
    "customDomainCount": 3,
    "customDomainQuota": 10,
    "memberCount": 4,
    "seatQuota": 10,
    "createdAt": 1774180000
  }
}
```

---

## 2. Create Workspace

Provision a new isolated organization workspace.

**POST** `/api/v1/organizations`

### Request Body Parameters

Validated against `CreateOrganizationSchema` in `shared/schemas/saas.ts`.

| Field | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `name` | `string` | **Yes** | Display name of the organization (2-64 characters). |
| `slug` | `string` | **Yes** | URL-safe workspace slug (2-48 characters, lowercase alphanumeric and hyphens). |
| `logo` | `string` | No | HTTPS URL pointing to the workspace brand mark or logo image. |

### Request Example

```bash
curl -X POST "https://shaf.app/api/v1/organizations" \
  -H "Authorization: Bearer $SHAF_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Acme Marketing",
    "slug": "acme-marketing"
  }'
```

### Response Example (HTTP 201 Created)

```json
{
  "code": 0,
  "data": {
    "id": "org_7f12a9c0",
    "name": "Acme Marketing",
    "slug": "acme-marketing",
    "plan": "free",
    "createdAt": 1774180000
  }
}
```

---

## 3. Update Workspace Settings

Modify organization display name, slug, logo URL, or allowed domain restrictions.

**PATCH** `/api/v1/organizations/current`

### Request Body Parameters

Validated against `UpdateOrganizationSchema` in `shared/schemas/saas.ts`.

| Field | Type | Description |
| :--- | :--- | :--- |
| `name` | `string` | Display name of the organization (2-64 characters). |
| `slug` | `string` | URL-safe workspace slug (2-48 characters, lowercase alphanumeric and hyphens). |
| `logo` | `string \| null` | HTTPS URL to workspace logo icon. Pass `null` to clear. |
| `allowedDomains` | `string[]` | Array of company email domains permitted for auto-joining via SSO. |

### Request Example

```bash
curl -X PATCH "https://shaf.app/api/v1/organizations/current" \
  -H "Authorization: Bearer $SHAF_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Acme Enterprise Marketing",
    "allowedDomains": ["brand.com"]
  }'
```

---

## 4. List Workspace Members

Retrieve all team members, pending invitations, and assigned RBAC roles.

**GET** `/api/v1/organizations/members`

### Response Example (HTTP 200 OK)

```json
{
  "code": 0,
  "data": {
    "members": [
      {
        "id": "usr_owner_01",
        "email": "sarah@brand.com",
        "name": "Sarah Connor",
        "role": "owner",
        "status": "active",
        "joinedAt": 1774180000
      },
      {
        "id": "usr_dev_02",
        "email": "alex@brand.com",
        "name": "Alex Murphy",
        "role": "admin",
        "status": "active",
        "joinedAt": 1774182000
      }
    ],
    "invitations": [
      {
        "id": "inv_98fba1",
        "email": "contractor@agency.com",
        "role": "member",
        "invitedAt": 1774190000,
        "expiresAt": 1774794800
      }
    ]
  }
}
```

---

## 5. Invite Team Member

Send an email invitation or provision access for a new workspace member.

**POST** `/api/v1/organizations/members/invite`

### Request Body Parameters

Validated against `InviteMemberSchema` in `shared/schemas/saas.ts`.

| Field | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `email` | `string` | **Yes** | Destination corporate email address (RFC 5322 format). |
| `role` | `string` | No | RBAC permission role: `'admin'`, `'member'`, or `'viewer'`. Defaults to `'member'`. |

### RBAC Permission Hierarchy

| Capability | Owner | Admin | Member | Viewer |
| :--- | :---: | :---: | :---: | :---: |
| Manage Workspace Billing & Ownership | ✅ | ❌ | ❌ | ❌ |
| Invite & Deprovision Members | ✅ | ✅ | ❌ | ❌ |
| Manage Custom Domains & SCIM/SSO | ✅ | ✅ | ❌ | ❌ |
| Create, Edit, & Delete Short Links | ✅ | ✅ | ✅ | ❌ |
| View Real-Time Telemetry & Reports | ✅ | ✅ | ✅ | ✅ |

### Request Example

```bash
curl -X POST "https://shaf.app/api/v1/organizations/members/invite" \
  -H "Authorization: Bearer $SHAF_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "analyst@brand.com",
    "role": "viewer"
  }'
```

---

## 6. Update Member Role

Change the RBAC role assignment for an existing workspace collaborator.

**PATCH** `/api/v1/organizations/members/:id`

### Path Parameters

- `id` (`string`, required): Unique user ID within the workspace.

### Request Body Parameters

Validated against `UpdateMemberRoleSchema` in `shared/schemas/saas.ts`.

| Field | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `role` | `string` | **Yes** | Target RBAC role: `'owner'`, `'admin'`, `'member'`, or `'viewer'`. |

### Request Example

```json
{
  "role": "admin"
}
```

---

## 7. Remove Member

Revoke workspace access for a collaborator or cancel a pending invitation.

**DELETE** `/api/v1/organizations/members/:id`

### Response Example (HTTP 200 OK)

```json
{
  "code": 0,
  "data": {
    "removed": true,
    "id": "usr_dev_02"
  }
}
```

---

## Error Response Matrix

| Status | Code | Constant | Meaning & Mitigation |
| :---: | :---: | :--- | :--- |
| `400` | `40020` | `INVALID_EMAIL` | Email format is invalid. |
| `400` | `40021` | `CANNOT_DEMOTE_SOLE_OWNER`| Organizations must have at least one active owner. Transfer ownership first. |
| `403` | `40301` | `FORBIDDEN` | Requesting API key lacks `org:admin` permissions. |
| `403` | `40302` | `SEAT_QUOTA_EXCEEDED` | All available member seats in current plan are occupied. |
| `404` | `40403` | `MEMBER_NOT_FOUND` | Member ID does not exist in this workspace. |
| `409` | `40903` | `MEMBER_ALREADY_EXISTS` | User is already an active member of this organization. |

Source: https://shaf.app/docs/reference/rest-api/organizations/index.mdx
