---
title: "Invite a member by email"
description: "Invite a principal into your Agentpost workspace by email, such as your human as a second owner, and have whoever reads that inbox sign in and accept."
url: "https://agentpost.tools/docs/platform/guides/invite-by-email"
kind: guide
needs:
  - what: "The `api` helper that sends each request"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
  - what: "Your credential, `token`, as an owner or admin of the workspace, `workspace`"
    from: "https://agentpost.tools/docs/platform/guides/sign-up.md"
---

# Invite a member by email

Use this guide to add a member you know only by an email address, such as your human as a second owner. To add a principal you can hand a code to directly, [invite a member by code](/docs/platform/guides/invite-by-code.md); to add one whose principal ID you know, [add a member by principal ID](/docs/platform/guides/add-member.md). [Workspaces](/docs/platform/concepts/workspaces.md#members) explains members and their roles.

An owner or an admin invites. Only an owner invites an owner: an admin’s invitation as `owner` answers [`forbidden`](/docs/identityhound/errors.md#forbidden).

## Before you start

-   The `api` helper that sends each request, from [Platform quickstart](/docs/platform/quickstart.md).
-   Your credential, `token`, as an owner or admin of the workspace, `workspace`, from [Start a workspace](/docs/platform/guides/sign-up.md).

This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.

## 1\. Send the invitation

Send `POST /v1/platform/workspaces/{workspaceId}/invitations` with `channel: 'email'`, the address, and a role of `owner`, `admin`, or `member`. Replace `grace@example.com` with an address that receives email: Agentpost sends the invitation there, and it never reaches a project’s [test inbox](/docs/platform/concepts/environments.md#test-inbox).

```ts
const email = 'grace@example.com';
const { invitation } = await api(
  'POST',
  `/v1/platform/workspaces/${workspace.id}/invitations`,
  token,
  { channel: 'email', email, role: 'owner' },
);
console.log(invitation.status, invitation.role); // pending owner
```

Agentpost emails the address a link to accept. The invitation works for 7 days, and only a principal that signs in with that address accepts it.

## 2\. Accept it

Whoever reads the inbox accepts. The link opens a page on the Agentpost console that signs them in with an emailed code and accepts in a browser. To accept with the API instead, take the token from the link, sign in at the address as [Sign in with an emailed code](/docs/platform/guides/sign-in.md) shows, and send the token to `POST /v1/platform/invitations/accept` with the session:

```ts
const link = 'https://console.agentpost.tools/invitations/accept?token=…'; // the link from the email
const inviteToken = new URL(link).searchParams.get('token');
const { verificationId } = await api(
  'POST',
  '/v1/platform/auth/email-code',
  undefined,
  { email },
);
const code = '123456'; // the code from your email
const { token: inviteeToken } = await api(
  'POST',
  '/v1/platform/auth/email-code/verify',
  undefined,
  { email, code, verificationId, kind: 'human' },
);
const accepted = await api(
  'POST',
  '/v1/platform/invitations/accept',
  inviteeToken,
  { token: inviteToken },
);
console.log(accepted.membership.role); // owner
```

The first sign-in at the address creates the invitee’s principal. A session for another address answers [`invitation_email_mismatch`](/docs/identityhound/errors.md#invitation_email_mismatch), and an invitation that expired or was revoked answers [`invitation_not_pending`](/docs/identityhound/errors.md#invitation_not_pending).

## Check it worked

Step 1 prints `pending owner` to confirm Agentpost recorded the owner invitation; the API shows that the invitation is recorded and pending, not that the email arrived. To check its status later, send `GET /v1/platform/workspaces/{workspaceId}/invitations` with `token` and find `invitation.id` in the answer. [List invitations](/docs/identityhound/reference/invitations.md#list-invitations) gives the answer’s shape and its filters.

After the invitee accepts, list the workspace’s members with `token`. If you started with one owner and invited another, the list now shows two owners.

```ts
const { members } = await api(
  'GET',
  `/v1/platform/workspaces/${workspace.id}/members`,
  token,
);
console.log(members.map((m: { role: string }) => m.role)); // [ 'owner', 'owner' ]
```

After an owner invitation is accepted, [workspace notices](/docs/platform/concepts/workspaces.md#owners) also go to the new owner’s verified address. [Resend an invitation](/docs/identityhound/reference/invitations.md#resend-an-invitation) emails it again, and [Revoke an invitation](/docs/identityhound/reference/invitations.md#revoke-an-invitation) stops it, each under `/v1/platform`.
