# Invite Agency Team Member Beta

> Add someone to the agency team, or invite them by email.

> Documentation index: https://www.foxreach.io/docs/llms.txt lists every page of these docs. Each page is also served as Markdown: add `.md` to its URL.

`POST` https://api.foxreach.io/api/v1/agency/team/invite

> **Note:** **Beta.** Agency team endpoints are new and may change.

Requires an API key with the `write` and `admin` scopes, created by the agency workspace owner. The `admin` scope is opt-in: no default key carries it. Only keys of an Agency workspace can call it (`403 agency_required` otherwise).

Only API keys of an Agency workspace can call this endpoint (`403 agency_required` otherwise). The call always runs in the key's own workspace; `X-Workspace-Id` is ignored. Writes also need a key created by the agency workspace owner (`403 agency_owner_required` otherwise).

- **The email belongs to a FoxReach account:** they join the team at once and can open the client workspaces you pass. Workspaces of the agency they could already open stay open at the role they had. No email is sent.
- **No account uses the email:** FoxReach sends one invite email covering every workspace you pass (at least one is required). They join the team when they accept. Sending again to the same email replaces the earlier invite's workspaces.

A `manager` is an admin in their client workspaces (invites people, edits settings) and can open Agency Admin's Dashboard and Clients for them. A `member` is a plain workspace member.

## Body Parameters

- `email` string body required: The person's email.
- `role` string body default `member`: `manager` or `member`.
- `workspaceIds` string[] body: Client workspace ids from [List Agency Clients](https://www.foxreach.io/docs/api-reference/agency/list-clients), at most 50. Required (at least one) for an email with no account.

## Response

Returns a `201` status code. `status` says which of the two cases happened.

- `data` object

  - `status` string: `added` or `invited`.
  - `id` string: Team member id (`added` only).
  - `userId` string: The person's user id (`added` only).
  - `email` string: The email, lower-cased.
  - `role` string: `manager` or `member`.
  - `workspaceIds` string[]: For `added`, every client workspace they can now open. For `invited`, the workspaces the invite covers.
  - `expiresAt` string: When the invite expires (`invited` only).

**Request example**

```bash cURL
curl -X POST "https://api.foxreach.io/api/v1/agency/team/invite" \
  -H "X-API-Key: otr_your_key" \
  -H "Content-Type: application/json" \
  -d '{"email": "sam@agency.com", "role": "manager", "workspaceIds": ["ws_abc123"]}'
```

```python Python SDK (beta)
from foxreach import FoxReach

client = FoxReach(api_key="otr_your_key")
member = client.agency.invite_team_member("sam@agency.com", role="manager", workspace_ids=["ws_abc123"])
```

```typescript TypeScript SDK (beta)
import { FoxReach } from "foxreach";

const client = new FoxReach({ apiKey: "otr_your_key" });
const member = await client.agency.inviteTeamMember({ email: "sam@agency.com", role: "manager", workspaceIds: ["ws_abc123"] });
```

**Response example**

```json
{
  "data": {
    "status": "added",
    "id": "am_abc123",
    "userId": "usr_def456",
    "email": "sam@agency.com",
    "role": "manager",
    "workspaceIds": ["ws_abc123"]
  }
}
```

Each change is recorded as `audit.agency_member.*` events (`added` or `invited`, then `access_granted` per workspace) with the key as the actor, readable through the [audit log](https://www.foxreach.io/docs/api-reference/audit-log/list-audit-log).

## Errors

| Status | Description |
|--------|-------------|
| `401` | Missing, invalid, revoked or expired API key |
| `403` | API key does not have the required scope: `write` |
| `403` | `agency_required` or `agency_owner_required` |
| `400` | `role` is not `manager` or `member`, a workspace is not the agency owner's, the email is the owner's own or already on the team, or an email with no account was sent no workspaces |
| `409` | Another change to this team was saved at the same time; try again |
| `422` | `email` is missing or not an email, or more than 50 `workspaceIds` |

## Rate Limit

- **120 requests per minute, shared by every `write` call in your workspace.** Fixed 60-second window.
- Every response includes `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset` (unix epoch seconds) and `X-RateLimit-Bucket` (`write`).
- A `429` response includes a `Retry-After` header (seconds until the bucket resets).

For client-side patterns, see [Rate Limiting](https://www.foxreach.io/docs/rate-limiting).
