# Invites endpoints

Every path starts at your [API URL](https://docs.qualithm.com/api.md#find-your-api-url). Every response is JSON, and an error has the [error body](https://docs.qualithm.com/api.md#errors).

## Accept the invite an invite link names

`POST /v1/invites/accept`

Only the account whose email the invite names can accept it; anyone else gets `403` with `invite_email_mismatch`.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate).

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Request body:** [AcceptInviteRequest](#acceptinviterequest)

**Response:** `201` with [TeamMembership](#teammembership) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `409`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/invites/accept" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"token":"<token>"}'
```

## Read the invite an invite link names

`POST /v1/invites/lookup`

Says whether the caller can accept it: only the account whose email it names can. Answers `404` with `invite_expired` once the link has expired.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate).

**Request body:** [AcceptInviteRequest](#acceptinviterequest)

**Response:** `200` with [InviteLink](#invitelink) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `404`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/invites/lookup" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"token":"<token>"}'
```

## List the team's pending invites

`GET /v1/teams/{teamId}/invites`

Newest first, by `createdAt` then `id`.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `member.invite` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `limit` | query | integer | No | Items per page, 1 to 100. Default 50. |
| `cursor` | query | string | No | A previous page's `nextCursor`, to read the page after it |

**Response:** `200` with [TeamInvitePage](#teaminvitepage) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `429`, `500`, `503`

```bash
curl "<your-api-url>/v1/teams/<team-id>/invites" \
  -H "Authorization: Bearer <your-api-token>"
```

## Invite email addresses to the team

`POST /v1/teams/{teamId}/invites`

Each address gets an invite whose link expires after 7 days; only the account with that email can accept it. The team, and the inviting account across all its teams, may each send a limited number of invite emails per hour.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `member.invite` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Request body:** [CreateTeamInviteRequest](#createteaminviterequest)

**Response:** `200` with [TeamInviteResults](#teaminviteresults) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `409`, `413`, `415`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/invites" \
  -H "Authorization: Bearer <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"emails":["<emails>"],"role":"owner"}'
```

## Withdraw a pending invite

`DELETE /v1/teams/{teamId}/invites/{inviteId}`

Its link stops working at once.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `member.invite` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `inviteId` | path | string | Yes | An invite ID: `ivt_…` |

**Response:** `204` with no body.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `429`, `500`, `503`

```bash
curl -X DELETE "<your-api-url>/v1/teams/<team-id>/invites/<invite-id>" \
  -H "Authorization: Bearer <your-api-token>"
```

## Mail a pending invite again

`POST /v1/teams/{teamId}/invites/{inviteId}/resend`

Issues a new link, which expires 7 days from now; the old link stops working. An expired invite can be resent until it is cleared.

Needs an [API token](https://docs.qualithm.com/api.md#authenticate) with the `member.invite` permission, which the owner and manager roles hold.

**Parameters**

| Name | In | Type | Required | Description |
| ---- | -- | ---- | -------- | ----------- |
| `teamId` | path | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `inviteId` | path | string | Yes | An invite ID: `ivt_…` |
| `Idempotency-Key` | header | string | No | A unique key for this request. A retry with the same key and body returns the first response instead of acting again; keys last 24 hours. |

**Response:** `200` with [TeamInvite](#teaminvite) in `data`.

**[Errors](https://docs.qualithm.com/api.md#errors):** `400`, `401`, `403`, `404`, `409`, `429`, `500`, `503`

```bash
curl -X POST "<your-api-url>/v1/teams/<team-id>/invites/<invite-id>/resend" \
  -H "Authorization: Bearer <your-api-token>"
```

## Types

### AcceptInviteRequest

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `token` | string | Yes | The token from the invite link |

### TeamMembership

A membership row, without the account and team context

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | A member ID: `mbr_…`; also accepts the legacy `mem_…` |
| `accountId` | string | Yes | An account ID: `acc_…` |
| `teamId` | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `role` | [MemberRole](#memberrole) | Yes |  |
| `status` | one of `"invited"`, `"active"`, `"revoked"`, `"declined"` | Yes |  |
| `createdAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `updatedAt` | string (date-time) | Yes | UTC time, RFC 3339 |

### MemberRole

A member's role in a team.

one of `"owner"`, `"manager"`, `"viewer"`.

### InviteLink

The invite a link names, and whether the caller may accept it

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `invite` | [TeamInvite](#teaminvite) | Yes |  |
| `forCaller` | boolean | Yes | Whether the signed-in account's email is the invited address, so it can accept |

### TeamInvite

A pending invite to a team, addressed to an email

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `id` | string | Yes | An invite ID: `ivt_…` |
| `teamId` | string | Yes | A team ID: `tem_…`; also accepts the legacy `tm_…` |
| `teamName` | string | Yes |  |
| `email` | string | Yes | The invited address; only its account can accept |
| `role` | [MemberRole](#memberrole) | Yes |  |
| `invitedBy` | string or null | Yes | Who sent it, when known |
| `inviterName` | string or null | Yes |  |
| `expiresAt` | string (date-time) | Yes | When its link stops working |
| `createdAt` | string (date-time) | Yes | UTC time, RFC 3339 |
| `updatedAt` | string (date-time) | Yes | UTC time, RFC 3339 |

### TeamInvitePage

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `items` | array of [TeamInvite](#teaminvite) | Yes |  |
| `nextCursor` | string or null | Yes | Pass as `cursor` to read the next page; `null` on the last page |

### CreateTeamInviteRequest

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `emails` | array of string | Yes | The addresses to invite, with or without an account |
| `role` | [MemberRole](#memberrole) | Yes |  |

### TeamInviteResults

One result per address, in the order given

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `items` | array of [TeamInviteResult](#teaminviteresult) | Yes |  |

### TeamInviteResult

What inviting one address did

| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `email` | string | Yes |  |
| `result` | one of `"sent"`, `"already_member"`, `"already_invited"` | Yes | `sent`: a new invite was mailed. `already_member`: the address's account is in the team. `already_invited`: a pending invite exists; resend it instead |
| `invite` | [TeamInvite](#teaminvite) or null | Yes | The invite, unless already a member |
