---
title: "Invite someone to a workspace"
description: "Invite a principal into an IdentityHound workspace by email, preview the invitation before it signs in, and accept it with its session."
url: "https://agentpost.tools/docs/identityhound/guides/invitations"
kind: guide
needs:
  - what: "The `api` helper"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
  - what: "The `identity`, `testInbox`, and `signIn` helpers, and a config that sets `urls.invitationAccept`"
    from: "https://agentpost.tools/docs/identityhound/quickstart.md"
  - what: "Ana's sign-in, `ana`, and the workspace Ana owns, `acme`"
    from: "https://agentpost.tools/docs/identityhound/quickstart.md"
---

# Invite someone to a workspace

[Workspaces](/docs/identityhound/concepts/workspaces.md#invitations) describes invitations by email and by code.

## Before you start

-   The `api` helper, from [Platform quickstart](/docs/platform/quickstart.md).
-   The `identity`, `testInbox`, and `signIn` helpers, and a config that sets `urls.invitationAccept`, from [IdentityHound quickstart](/docs/identityhound/quickstart.md).
-   Ana's sign-in, `ana`, and the workspace Ana owns, `acme`, from [IdentityHound quickstart](/docs/identityhound/quickstart.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

Ana invites Ben as a member with `POST /v1/identity/workspaces/{id}/invitations` from Ana’s session. IdentityHound emails Ben a link to your config’s `urls.invitationAccept` with the invitation’s token in its `token` query parameter. The invitation lasts the config’s `invitations.ttl`, 7 days in Agentpost’s starting config. Ben’s address is at `.test`, so the email waits in the [Platform test inbox](/docs/platform/concepts/environments.md#test-inbox):

```ts
await api('POST', `/v1/identity/workspaces/${acme.id}/invitations`, ana.token, {
  role: 'member',
  channel: 'email',
  email: 'ben@acme.test',
});
const invitation = await testInbox('ben@acme.test');
const inviteToken = new URL(invitation.data.link).searchParams.get('token');
console.log(invitation.template); // invitation
```

Invite from a session with `identity.invitation:create` in the workspace. Sending the invitation can answer [`forbidden`](/docs/identityhound/errors.md#forbidden).

## 2\. Preview it

Your accept page’s server reads the token from the link and previews it with the secret key, so the page shows Ben what the invitation joins before Ben signs in. A preview changes nothing:

```ts
const preview = await identity('POST', '/invitations/preview', {
  token: inviteToken,
});
console.log(preview.workspace.name, preview.invitation.role); // Acme member
```

## 3\. Accept it

Ben signs in, then accepts with that session. An email invitation needs its address as one of Ben’s verified identities, which signing in with that address gives:

```ts
const ben = await signIn('ben@acme.test');
await api('POST', '/v1/identity/invitations/accept', ben.token, {
  token: inviteToken,
});
```

Accepting can answer [`invitation_not_pending`](/docs/identityhound/errors.md#invitation_not_pending) or [`invitation_invalid`](/docs/identityhound/errors.md#invitation_invalid). On [`invitation_email_mismatch`](/docs/identityhound/errors.md#invitation_email_mismatch), sign in with the invited address and accept again.

## Check it worked

List Acme’s members with the secret key:

```ts
const { members } = await identity('GET', `/workspaces/${acme.id}/members`);
console.log(members.map((m: { role: string }) => m.role)); // [ 'owner', 'member' ]
```

Access checks for Ben now follow the member role in your config. The [invitations reference](/docs/identityhound/reference/invitations.md) covers invitations by code, resending, and revoking.
