# Manage an organization

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

Add mountaya_admin to a Dart server to invite members, manage API keys, mint session tokens and create webhook endpoints.

The admin package holds what a server that runs your organization needs: its members, its keys, its session tokens and its webhook endpoints.

## Add the admin package

```bash
dart pub add mountaya_client mountaya_admin
```

Importing it adds `admin` to the client:

```dart
import 'dart:io';

import 'package:mountaya_admin/mountaya_admin.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;

final environment = Platform.environment;
final publishableKey = environment['MOUNTAYA_PUBLISHABLE_KEY'] ?? '';
final mountaya = Mountaya(
  credential: .publishable(
    key: publishableKey,
    sessionToken: .value(environment['MOUNTAYA_SESSION_TOKEN'] ?? ''),
  ),
);
// The key names its organization.
final organization = await mountaya.studio.organizations.postOrganizationLookup(
  body: rest_schema.OrganizationLookupParams(publishable_key: publishableKey),
);
final organizationId = organization.data.id;

final settings = await mountaya.admin.organizations.getOrganizationSettings(
  organization_id: organizationId,
);
print(settings.data.etag);
await mountaya.close();
```

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.

- `package:mountaya_admin/mountaya_admin.dart` declares `extension ClientAdmin on Mountaya`, whose `admin` getter holds `billing`, `invitations`, `keys`, `members`, `organizations` (details, settings, usage, AI provider configuration, `postOrganization`), `sessions` (`postSession`), `users` (the acting user's own memberships, preferences and invitations, under `/v1/me`) and `webhooks`. Each call is a call of the client you made, held to its credential, retries and error ladder. Method names are the contract's operation ids; each answers a `Response` with the payload at `data`. Its own types are `package:mountaya_admin/admin_schema.dart`, imported `as admin_schema`.
- The package is pure Dart and depends on `mountaya_client` alone. No other package depends on it, so an app that never names it links none of it. An app never adds it.
- Credentials: the organization's operations take a publishable key with the `management` scope and a session token beside it. `management` is carried alone, and never ships in an app. 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 `ConfigurationException` where the client knows the token was minted without `user_id` (`.minted(session)` or a `SessionTokenEngine`).
- 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).
- `MOUNTAYA_SESSION_TOKEN` is a token your server minted for that member with the secret key ([mint session tokens](https://docs.mountaya.com/en/sdks/dart/admin.md#sessions)); a long-running server hands the client a `SessionTokenEngine` instead. `postOrganizationLookup` answers the key's organization, takes the key in its body and no credential.

## Members and invitations

```dart
import 'dart:io';

import 'package:mountaya_admin/admin_schema.dart' as admin_schema;
import 'package:mountaya_admin/mountaya_admin.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;

final environment = Platform.environment;
final publishableKey = environment['MOUNTAYA_PUBLISHABLE_KEY'] ?? '';
final mountaya = Mountaya(
  credential: .publishable(
    key: publishableKey,
    sessionToken: .value(environment['MOUNTAYA_SESSION_TOKEN'] ?? ''),
  ),
);
// The key names its organization.
final organization = await mountaya.studio.organizations.postOrganizationLookup(
  body: rest_schema.OrganizationLookupParams(publishable_key: publishableKey),
);
final organizationId = organization.data.id;

await for (final member in mountaya.admin.members.walkGetOrganizationMembers(
  organization_id: organizationId,
)) {
  print('${member.user_id} ${member.role}');
}

await mountaya.admin.members.patchOrganizationMember(
  organization_id: organizationId,
  user_id: '7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1',
  body: admin_schema.OrganizationMemberUpdateParams(
    role: admin_schema.AssignableOrganizationRole.viewer,
  ),
);

await mountaya.admin.invitations.postOrganizationInvitation(
  organization_id: organizationId,
  body: admin_schema.OrganizationInvitationCreateParams(
    email: 'camille@example.com',
    role: admin_schema.AssignableOrganizationRole.contributor,
  ),
);
await mountaya.close();
```

Each member has a `user_id` and a `role`. Making someone an admin is the owner's act, in the Mountaya app.

- `admin.members`: `getOrganizationMembers` (one page of `OrganizationMember`: `user_id`, `email`, `name`, `role`, `joined_at`, 50 by default) and `walkGetOrganizationMembers`, `patchOrganizationMember` (`role`), `deleteOrganizationMember` (a member, or yourself to leave). `admin.invitations`: `getOrganizationInvitations` (and its walk), `getOrganizationInvitation`, `postOrganizationInvitation` (`email`, `role`, one address per request, expiring after 30 days), `deleteOrganizationInvitation`.
- `admin_schema.AssignableOrganizationRole`: `admin`, `contributor`, `viewer`; under a key, `contributor` or `viewer` only. Granting `admin`, taking it, removing an admin and inviting one answer `403` whoever the token names.
- Seats and invitations waiting at once are ceilings of the agreement: one more is a `RateLimitException` coded `limitReached`, with no `retryAfter`.
- A role the token's user lacks answers `403`, never `404`.

## API keys

```dart
import 'dart:io';

import 'package:mountaya_admin/admin_schema.dart' as admin_schema;
import 'package:mountaya_admin/mountaya_admin.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;

final environment = Platform.environment;
final publishableKey = environment['MOUNTAYA_PUBLISHABLE_KEY'] ?? '';
final mountaya = Mountaya(
  credential: .publishable(
    key: publishableKey,
    sessionToken: .value(environment['MOUNTAYA_SESSION_TOKEN'] ?? ''),
  ),
);
// The key names its organization.
final organization = await mountaya.studio.organizations.postOrganizationLookup(
  body: rest_schema.OrganizationLookupParams(publishable_key: publishableKey),
);
final organizationId = organization.data.id;

final key = await mountaya.admin.keys.postOrganizationPublishableKey(
  organization_id: organizationId,
  body: admin_schema.PublishableKeyCreateParams(
    name: 'Website',
    scopes: [
      admin_schema.PublishableKeyScope.publishing,
      admin_schema.PublishableKeyScope.tiles,
    ],
  ),
);
print(key.data.key);
await mountaya.close();
```

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

- `admin.keys`: `getOrganizationPublishableKeys` (and its walk), `getOrganizationPublishableKey`, `postOrganizationPublishableKey` (`name`, `scopes`), `patchOrganizationPublishableKey` (name and scopes, with `ifMatch:` the key's `etag`), `deleteOrganizationPublishableKey` (revokes it). A `PublishableKey` carries `id`, `key`, `name`, `scopes`, `etag`, `created_at`, `last_used_at` and `revoked_at`.
- `admin_schema.PublishableKeyScope`: `publishing`, `studioEmbedded`, `tiles`, `data`, `mcp`, `management`. At least one; `management` alone on its key (a list naming it beside another is a `400`); `studioEmbedded` with `tiles` and `data`; a scope whose product the organization lacks is a `402`.
- No operation lists, creates or reveals a secret key. 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:

```dart
import 'dart:io';

import 'package:mountaya_admin/admin_schema.dart' as admin_schema;
import 'package:mountaya_admin/mountaya_admin.dart';
import 'package:mountaya_client/mountaya_client.dart';

final environment = Platform.environment;
final server = Mountaya(
  credential: SecretCredential(environment['MOUNTAYA_SECRET_KEY'] ?? ''),
);

// userId is the member your own sign-in vouches for, never one read from the request.
const userId = '7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1';
final session = await server.admin.sessions.postSession(
  body: admin_schema.SessionCreateParams(
    publishable_key: environment['MOUNTAYA_PUBLISHABLE_KEY'] ?? '',
    user_id: userId,
  ),
);
// The token lives minutes.
print(session.data.expires_at);
await server.close();
```

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

- `mountaya.admin.sessions.postSession(body: admin_schema.SessionCreateParams(publishable_key:, user_id:, surface:))` answers a `rest_schema.Session`: `token`, `expires_at`, `user_id`. A token lives minutes; `SessionTokenEngine(mint:)` mints again before it expires.
- A secret key authenticates `postSession` and nothing else: keep one `SecretCredential` client for minting, and make every other call through a client built with `.publishable(key:, sessionToken:)`. `SecretCredential` exists on the Dart VM only.
- `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: rest_schema.SessionSurface.studioEmbedded` mints for writes to itineraries, collections and zones.

## Webhook endpoints

```dart
import 'dart:io';

import 'package:mountaya_admin/admin_schema.dart' as admin_schema;
import 'package:mountaya_admin/mountaya_admin.dart';
import 'package:mountaya_client/mountaya_client.dart';
import 'package:mountaya_client/rest_schema.dart' as rest_schema;

final environment = Platform.environment;
final publishableKey = environment['MOUNTAYA_PUBLISHABLE_KEY'] ?? '';
final mountaya = Mountaya(
  credential: .publishable(
    key: publishableKey,
    sessionToken: .value(environment['MOUNTAYA_SESSION_TOKEN'] ?? ''),
  ),
);
// The key names its organization.
final organization = await mountaya.studio.organizations.postOrganizationLookup(
  body: rest_schema.OrganizationLookupParams(publishable_key: publishableKey),
);
final organizationId = organization.data.id;

final endpoint = await mountaya.admin.webhooks.postOrganizationWebhookEndpoint(
  organization_id: organizationId,
  body: admin_schema.WebhookEndpointCreateParams(
    url: Url('https://example.com/mountaya/webhooks'),
    enabled_events: ['itinerary.published', 'organization.member.*'],
  ),
);
// whsk_…, shown once: store it now.
print(endpoint.data.secret);
await mountaya.close();
```

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

- `enabled_events` lists event types, families followed by `.*`, or `*` for every public type, later ones included; 1 to 128 entries. A type the contract does not publish is a `400` naming its position. `url` is a `Url`, `https`, printable ASCII, at most 2,048 characters, with no credentials and no fragment; `Url('…')` with no scheme is a `ConfigurationException`.
- 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.
- `admin.webhooks` also holds `getOrganizationWebhookEndpoints` (and its walk), `getOrganizationWebhookEndpoint`, `patchOrganizationWebhookEndpoint` (URL, events, status, and `description` as a setter), `deleteOrganizationWebhookEndpoint`, the events (`getOrganizationWebhookEvents`, `getOrganizationWebhookEvent`), the deliveries (`getOrganizationWebhookDeliveries`, `getOrganizationWebhookDelivery`), `getOrganizationWebhookHealth` and `getWebhookEventTypes`.
- `postOrganizationWebhookDelivery(organization_id:, body: admin_schema.WebhookDeliveryCreateParams(webhook_endpoint_id:, …))` takes exactly one of `event_id` (resend one event of the last 30 days), `test:` (a test event, delivered once) or `since:` (redeliver every event from an instant on). A disabled endpoint is a `409`.
- Webhook endpoints are a ceiling of the agreement (2 unless it says otherwise, 6 at most): one past it is a `RateLimitException` coded `limitReached`. See [webhook endpoints](https://docs.mountaya.com/en/webhooks/endpoints.md).

## Next steps

- [Receive webhooks](https://docs.mountaya.com/en/sdks/dart/webhooks.md): Verify a delivery and handle its event.
- [Authentication in the SDK](https://docs.mountaya.com/en/sdks/dart/authentication.md): Session tokens for apps and members.
