# API: Agency workspaces

| Method | Path | What it does | Scope |
|---|---|---|---|
| GET | `/v1/agency/clients` | Client workspaces this agency manages, each with its monthly credit cap and this month's credits used; the pool they share; and the agency managing this organization, if any | `settings:read` |
| POST | `/v1/agency/clients` | Add a client workspace: an organization you also own, with its share of the pool as its monthly credit cap (owners, Agency plan) (web app only) | `settings:write` |
| DELETE | `/v1/agency/clients/:id` | Stop managing a client workspace: its data stays in its own organization, which goes back to its own plan's credits (owners) (web app only) | `settings:write` |
| GET | `/v1/agency/clients/:id` | One client workspace's report: its cap and this month's credits by module (totals only) | `settings:read` |
| PATCH | `/v1/agency/clients/:id` | Rename a client workspace or change its share of the pool (owners of the agency; the change is in the client's audit log too) (web app only) | `settings:write` |
| GET | `/v1/agency/link-offers` | This agency's invitations to client organizations and where each stands (never the codes) | `settings:read` |
| POST | `/v1/agency/link-offers` | Invite a client organization: a one-time code, shown once, that the client's owner accepts within 7 days (owners, Agency plan) (web app only) | `settings:write` |
| DELETE | `/v1/agency/link-offers/:id` | Withdraw an open invitation (owners) (web app only) | `settings:write` |
| POST | `/v1/agency/link-offers/accept` | Accept an agency's invitation for this organization to be managed by it (owners of this organization) (web app only) | `settings:write` |
| POST | `/v1/agency/link-offers/preview` | What an agency's invitation offers this organization (the agency and the monthly credit cap), before an owner accepts it (web app only) | `settings:write` |
| DELETE | `/v1/agency/managed-by` | End the agency's management of this organization (owners of this organization; its data stays, and it goes back to its own plan's credits) (web app only) | `settings:write` |

## Examples

### GET /v1/agency/clients

Client workspaces this agency manages, each with its monthly credit cap and this month's credits used; the pool they share; and the agency managing this organization, if any

```bash
curl -s "https://api.cubbylark.com/v1/agency/clients" \
  -H "Authorization: Bearer $KC_API_KEY"
```

```js
const res = await fetch(`https://api.cubbylark.com/v1/agency/clients`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.KC_API_KEY}` },
});
const data = await res.json();
```

### GET /v1/agency/clients/$ID

One client workspace's report: its cap and this month's credits by module (totals only)

```bash
curl -s "https://api.cubbylark.com/v1/agency/clients/$ID" \
  -H "Authorization: Bearer $KC_API_KEY"
```

```js
const res = await fetch(`https://api.cubbylark.com/v1/agency/clients/${id}`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.KC_API_KEY}` },
});
const data = await res.json();
```

### GET /v1/agency/link-offers

This agency's invitations to client organizations and where each stands (never the codes)

```bash
curl -s "https://api.cubbylark.com/v1/agency/link-offers" \
  -H "Authorization: Bearer $KC_API_KEY"
```

```js
const res = await fetch(`https://api.cubbylark.com/v1/agency/link-offers`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.KC_API_KEY}` },
});
const data = await res.json();
```

Request and response schemas: [https://www.cubbylark.com/openapi.json](https://www.cubbylark.com/openapi.json). All resources: [API reference](https://www.cubbylark.com/docs/api).
