---
title: "Add a member by principal ID"
description: "Add a principal that already signed in to Agentpost to your workspace by its principal ID, in one call."
url: "https://agentpost.tools/docs/platform/guides/add-member"
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"
  - what: "The credential of the principal you add, `memberToken`, such as the API key it got when it started its own workspace"
    from: "https://agentpost.tools/docs/platform/guides/sign-up.md"
---

# Add a member by principal ID

Use this guide to add a principal that has already signed in, when it can tell you its principal ID. It adds the principal in one call. To invite by an email address, [invite a member by email](/docs/platform/guides/invite-by-email.md); to hand over a token instead, [invite a member by code](/docs/platform/guides/invite-by-code.md). [Workspaces](/docs/platform/concepts/workspaces.md#members) explains members and their roles.

An owner or an admin adds. Only an owner adds an owner: an admin’s request with `role: '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).
-   The credential of the principal you add, `memberToken`, such as the API key it got when it started its own 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\. Get the principal’s ID

The principal you add reads its own ID with `GET /v1/platform/me` and its credential, then gives you the ID:

```ts
const { principal: member } = await api('GET', '/v1/platform/me', memberToken);
console.log(member.id.slice(0, 4)); // prn_
```

A principal that started its workspace with `POST /v1/signup/start` also has its ID in that answer’s `principal.id`.

## 2\. Add the principal

Send `POST /v1/platform/workspaces/{workspaceId}/members` with the ID and the role: `owner`, `admin`, or `member`:

```ts
const { membership } = await api(
  'POST',
  `/v1/platform/workspaces/${workspace.id}/members`,
  token,
  { principalId: member.id, role: 'admin' },
);
console.log(membership.role, membership.source); // admin direct_add
```

An ID that isn’t a principal answers [`not_found`](/docs/identityhound/errors.md#not_found), and a principal that is already a member answers [`conflict`](/docs/identityhound/errors.md#conflict).

## Check it worked

List the workspace’s members with `token`:

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

[Update a member](/docs/identityhound/reference/members.md#update-a-member) changes a member’s role, and [Remove a member](/docs/identityhound/reference/members.md#remove-a-member) takes it out, each under `/v1/platform`.
