Skip to content
Agentpost robot in sunglasses on a red circleAgentpost

Invite someone to a workspace

Workspaces describes invitations by email and by code.

Before you start

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:

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.

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:

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:

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

Accepting can answer invitation_not_pending or invitation_invalid. On invitation_email_mismatch, sign in with the invited address and accept again.

Check it worked

List Acme’s members with the secret key:

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 covers invitations by code, resending, and revoking.