# Manage an organization

> Canonical URL: https://docs.mountaya.com/en/sdks/typescript/admin/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Manage your Mountaya organization from a server with the admin unit: members and invitations, API keys, session tokens and webhook endpoints.

The admin unit holds what a server that runs your organization needs: its members, its keys, its session tokens and its webhook endpoints. It is `@mountaya/client/admin`, a subpath of `@mountaya/client`.

## Add the admin package

There is nothing more to install. Build `MountayaAdmin` over the client you already hold:

```ts
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const publishableKey = process.env.MOUNTAYA_PUBLISHABLE_KEY ?? "";
const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken: process.env.MOUNTAYA_SESSION_TOKEN ?? "" },
});
// The key names its organization.
const { data: organization } = await mountaya.studio.organizations.postOrganizationLookup({
  body: { publishable_key: publishableKey },
});
const organizationId = organization.id;

const admin = new MountayaAdmin(mountaya);
const { data: settings } = await admin.organizations.getOrganizationSettings({
  organization_id: organizationId,
});
console.log(settings.etag);
```

Here `MOUNTAYA_PUBLISHABLE_KEY` is a key that carries the `management` scope, kept on your server. The session token names the member who administers: an owner or an admin.

- `new MountayaAdmin(mountaya)` takes a `Mountaya` of `@mountaya/client` or of `@mountaya/client/browser` and calls through its transport: the credential, the retries, the idempotency keys and the error classes are the client's. Building one is cheap: the operations are bound once per transport, so `new MountayaAdmin(mountaya)` in every handler builds nothing twice.
- Its resources: `billing` (subscription, payment methods, details, invoices, products), `invitations`, `keys` (publishable keys), `members`, `organizations` (details, settings, usage, AI provider configuration, and `postOrganization`), `sessions` (`postSession`), `users` (the acting user's own memberships, preferences, notification preferences and invitations, under `/v1/me`) and `webhooks` (endpoints, events, deliveries, health, event types). Method names are the contract's operation ids, and each method resolves to the envelope, with the payload at `data`.
- `rest` of `@mountaya/client/admin` holds the same operations as free functions taking the transport first. Every type only these operations and the webhook events reach (`OrganizationMember`, `OrganizationInvitation`, `PublishableKey`, `WebhookEndpoint`, `WebhookEndpointWithSecret`, `Membership`…) is exported from `@mountaya/client/admin`, not from the package root.
- Credentials: the organization's operations take a publishable key with the `management` scope and a session token beside it. `management` is carried alone: a key with it carries no other scope, and it never ships in a page. Every read takes a token, and answers any member's token for members, invitations and settings; the keys, the usage, the billing and the webhooks are read by an owner or an admin. Every write takes a token naming an owner or an admin. The `/v1/me` operations under `users` take the `studio-embedded` scope and a token naming the user. `postSession` takes the secret key alone.
- A token minted without `user_id` reads the `management` reads when minted for the default `surface` (`api`), and writes nothing: a write answers `401`, refused locally with `MountayaConfigurationError` where a `SessionTokenEngine` reports the token was minted without `user_id`.
- Under a key, a token governs members with at most an admin's say: granting or taking `admin`, removing an admin, and inviting one answer `403`, whoever the token names. Those are the owner's acts in the Mountaya app. See [members and keys](https://docs.mountaya.com/en/apis/map-studio/members-and-keys.md).

## Members and invitations

```ts
import { MountayaAdmin } from "@mountaya/client/admin";

const admin = new MountayaAdmin(mountaya);

const { data: members } = await admin.members.getOrganizationMembers({
  organization_id: organizationId,
});

await admin.members.patchOrganizationMember({
  body: { role: "viewer" },
  organization_id: organizationId,
  user_id: "7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1",
});

await admin.invitations.postOrganizationInvitation({
  body: { email: "camille@example.com", role: "contributor" },
  organization_id: organizationId,
});
```

Each member has a `user_id` and a `role`. A key never grants `admin`: the owner does that in the Mountaya app. An invitation holds a seat until the person accepts it.

- `getOrganizationMembers({ organization_id, query })` answers one page of `OrganizationMember` (`user_id`, `email`, `name`, `role`, `joined_at`), 50 by default. `paginate(admin.members.getOrganizationMembers, { organization_id })` of `@mountaya/client` walks every page ([pagination](https://docs.mountaya.com/en/sdks/typescript/pagination.md#paginate)).
- `patchOrganizationMember({ organization_id, user_id, body: { role } })` changes a role; `deleteOrganizationMember({ organization_id, user_id })` removes a member, or yourself to leave. `role` is an `AssignableOrganizationRole`: `admin`, `contributor` or `viewer`, and under a key `contributor` or `viewer`.
- `postOrganizationInvitation({ organization_id, body: { email, role } })` invites one address per request, answered alike for every well-formed address. The invitation expires after 30 days. `getOrganizationInvitations`, `getOrganizationInvitation` and `deleteOrganizationInvitation` list, read and withdraw them. Invitations held at once and seats are ceilings of the agreement: a `429` coded `LIMIT_REACHED`.
- A role a token's user lacks answers `403 Forbidden`, never `404`.

## API keys

```ts
import { MountayaAdmin } from "@mountaya/client/admin";

const { data: key } = await new MountayaAdmin(mountaya).keys.postOrganizationPublishableKey({
  body: { name: "Website", scopes: ["publishing", "tiles"] },
  organization_id: organizationId,
});

console.log(key.key); // the pk_… value your pages send
```

A key reaches only the scopes it carries. Secret keys are created in the Mountaya app, under **Organization → API keys**.

- `keys` holds `getOrganizationPublishableKeys`, `getOrganizationPublishableKey`, `postOrganizationPublishableKey`, `patchOrganizationPublishableKey` (name and scopes, conditional on `ifMatch` with the key's `etag`) and `deleteOrganizationPublishableKey` (revokes it). A `PublishableKey` carries `id`, `key`, `name`, `scopes`, `etag`, `created_at`, `last_used_at` and `revoked_at`.
- `scopes` are `PublishableKeyScope`: `publishing`, `studio-embedded`, `tiles`, `data`, `mcp`, `management`. At least one; `management` alone on its key (a list naming it beside another is a `400` per scope beside it); `studio-embedded` with `tiles` and `data` (a `400` per missing one). A scope whose product the organization does not hold is a `402` naming its position.
- No operation lists, creates or reveals a secret key: they are absent from the contract. See [account and keys](https://docs.mountaya.com/en/account.md).

## Mint session tokens

Minting takes the secret key, so it runs on your server:

```ts
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const server = new Mountaya({
  credential: { secretKey: process.env.MOUNTAYA_SECRET_KEY ?? "" },
});

// userId is the member your own sign-in vouches for, never one read from the request.
const { data: session } = await new MountayaAdmin(server).sessions.postSession({
  body: { publishable_key: process.env.MOUNTAYA_PUBLISHABLE_KEY ?? "", user_id: userId },
});

console.log(session.expires_at); // the token lives minutes
```

Hand `session.token` to the client that calls the API. [Authentication in the SDK](https://docs.mountaya.com/en/sdks/typescript/authentication.md) keeps it fresh in the browser.

- `postSession({ body: { publishable_key, user_id?, surface? } })` answers `{ token, expires_at, user_id }`. A token lives minutes; `SessionTokenEngine` and `useSessionToken` mint again before it expires.
- A secret key authenticates `postSession` and nothing else: keep one client with `{ secretKey }` for minting, and make every other call through a client built with `{ publishableKey, sessionToken }`.
- `user_id` is the member every request made with the token acts as. Read it from your own sign-in, never from the request. Leave it out for a token that reads and never writes. `surface: "studio-embedded"` mints for an Embedded Studio.
- A secret-key client throws `MountayaConfigurationError` at construction where `window` and `document` exist, or in a React Native app.

## Webhook endpoints

```ts
import { MountayaAdmin } from "@mountaya/client/admin";

const { data: endpoint } = await new MountayaAdmin(mountaya).webhooks.postOrganizationWebhookEndpoint({
  body: {
    enabled_events: ["itinerary.published", "organization.member.*"],
    url: "https://example.com/mountaya/webhooks",
  },
  organization_id: organizationId,
});

console.log(endpoint.secret); // whsk_…, shown once: store it now
```

The secret signs every delivery. [Receive webhooks](https://docs.mountaya.com/en/sdks/typescript/webhooks.md) verifies them.

- `enabled_events` lists event types (`WebhookEventType`), families followed by `.*`, or `*` for every public type, later ones included. A type the contract does not publish is a `400` naming its position. `url` is `https`, printable ASCII, at most 2048 characters, with no credentials and no fragment, on a host that resolves to a public address.
- The answer is a `WebhookEndpointWithSecret`: the endpoint and its `secret`, `whsk_` and 64 hexadecimal characters, shown once. No read returns it again; an owner or an admin reveals it in the Mountaya app, where it is rotated too.
- `webhooks` also holds `getOrganizationWebhookEndpoints`, `getOrganizationWebhookEndpoint`, `patchOrganizationWebhookEndpoint` (its URL, description, events, and enabling or disabling it), `deleteOrganizationWebhookEndpoint`, the events (`getOrganizationWebhookEvents`, `getOrganizationWebhookEvent`) and deliveries (`getOrganizationWebhookDeliveries`, `getOrganizationWebhookDelivery`), `getOrganizationWebhookHealth` and `getWebhookEventTypes`.
- `postOrganizationWebhookDelivery({ organization_id, body: { webhook_endpoint_id, … } })` takes exactly one of `event_id` (resend one event of the last 30 days), `test: { type }` (a test event, delivered once without retries) or `since` (redeliver every event from an instant on). A disabled endpoint is a `409`.
- Webhook endpoints are a ceiling of the agreement: one past it is a `429` coded `LIMIT_REACHED`. The wire contract is on [webhook endpoints](https://docs.mountaya.com/en/webhooks/endpoints.md).

## Next steps

- [Receive webhooks](https://docs.mountaya.com/en/sdks/typescript/webhooks.md): Verify a delivery and handle its event.
- [Authentication in the SDK](https://docs.mountaya.com/en/sdks/typescript/authentication.md): Session tokens, and acting as a member.
