# API reference: orgs

Organizations and membership (CRUD-lite)

## GET /v1/orgs

`listMyOrgs` · scope `key:read` · List my organizations

Orgs the caller belongs to, with their role in each.

Parameters:

- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of org memberships.
- `401`: Missing or invalid credentials.

## POST /v1/orgs

`createOrg` · scope `key:write` · Create an organization

Creates an org with the caller as `owner` member. Org slugs and usernames share one handle namespace.

Request body: `application/json`, required.

Responses:

- `201`: Org created.
- `401`: Missing or invalid credentials.
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/orgs/{org}

`getOrg` · scope `none` · Get an organization

Public org profile.

Parameters:

- `org` (path, required): Org slug.

Responses:

- `200`: The org.
- `404`: Resource not found (or hidden from the caller).

## PATCH /v1/orgs/{org}

`updateOrg` · scope `key:write` · Update an organization

Only members with role `owner` may update.

Parameters:

- `org` (path, required): Org slug.

Request body: `application/json`, required.

Responses:

- `200`: Updated org.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.

## GET /v1/orgs/{org}/members

`listOrgMembers` · scope `key:read` · List organization members

Visible to org members only.

Parameters:

- `org` (path, required): Org slug.
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of members.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## PUT /v1/orgs/{org}/members/{username}

`putOrgMember` · scope `session` · Add or update a member

Upserts a membership with the given role. Only `owner` members may call, signed in: no API key can add a member or change a role. A member can approve the organization's deployments and spending, so a key must not be able to make one. An org must keep at least one `owner`.

Parameters:

- `org` (path, required): Org slug.
- `username` (path, required): User handle.

Request body: `application/json`, required.

Responses:

- `200`: Membership created or updated.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.

## DELETE /v1/orgs/{org}/members/{username}

`removeOrgMember` · scope `key:write` · Remove a member

`owner` members may remove anyone; any member may remove themselves (leave). Removing the last `owner` is rejected.

Parameters:

- `org` (path, required): Org slug.
- `username` (path, required): User handle.

Responses:

- `204`: Membership removed.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).

## GET /v1/orgs/{org}/invites

`listOrgInvites` · scope `key:read` · List an organization's invites

Owners only: each address invited, its role, who invited it, and whether the invite is pending, accepted, revoked or expired. Newest first.

Parameters:

- `org` (path, required): Org slug.
- `status` (query): Only invites in this state.
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: A page of invites.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## POST /v1/orgs/{org}/invites

`createOrgInvite` · scope `session` · Invite someone to an organization by e-mail

An owner invites a person by e-mail address and chooses the role they will have. The hub sends one e-mail that names who invited them and to which organization, with a link to accept. The address does not need an account yet: the person signs in or signs up from the link. The link works once and expires after seven days. Only a signed-in person may invite, so no API key can make the hub send e-mail. An organization holds at most 50 pending invites, and one pending invite per address (`409` for a second).

Parameters:

- `org` (path, required): Org slug.

Request body: `application/json`, required.

Responses:

- `201`: The invite, with its link. The link is in this response only: the hub keeps a hash of it.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## DELETE /v1/orgs/{org}/invites/{invite_id}

`revokeOrgInvite` · scope `key:write` · Revoke an invite

An owner revokes a pending invite, and its link stops working. Revoking an invite that is already revoked or expired changes nothing. An accepted invite is `409`: the person is a member, so remove the member instead.

Parameters:

- `org` (path, required): Org slug.
- `invite_id` (path, required): Invite id (`orginv_...`).

Responses:

- `204`: The invite is revoked.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).

## GET /v1/org-invites/{token}

`getOrgInvite` · scope `none` · Read an invite through its link

Returns what the invite link shows before anyone accepts it: the organization, who invited, the role, the expiry and the state. The address is shown with its local part masked. The token from the link is the only way to name an invite here. So anyone holding the link may read it. A signed-in caller also learns whether they may accept it. An unknown token is `404`.

Parameters:

- `token` (path, required): The token from an invite link (`/invites/{token}`).

Responses:

- `200`: The invite, as its link shows it.
- `404`: Resource not found (or hidden from the caller).

## POST /v1/org-invites/{token}/accept

`acceptOrgInvite` · scope `session` · Accept an invite and join the organization

The signed-in person joins the organization with the invite's role, and the link stops working. When the invited address belongs to an account on this hub, only that account may accept (`403` for any other). An unknown token is `404`. A used, revoked or expired invite is `409`, and so is a person who is already a member. Only a signed-in person may accept: joining is a person's decision.

Parameters:

- `token` (path, required): The token from an invite link (`/invites/{token}`).

Responses:

- `200`: The new membership.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
