# Manage an organization

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

Run an organization from a JVM server with mountaya-admin: members and invitations, publishable keys, session tokens and webhook endpoints.

`mountaya-admin` holds what a server that runs your organization needs: its members, its keys, its session tokens and its webhook endpoints. It is for servers and admin tools.

## Add the admin package

```kotlin
dependencies {
    implementation("com.mountaya:mountaya-admin:0.1.0")
}
```

Import `admin`, and the operations appear under `mountaya.admin` on the client you already hold:

```kotlin
import com.mountaya.admin.admin
import com.mountaya.client.Credential
import com.mountaya.client.Mountaya
import com.mountaya.client.SessionToken
import com.mountaya.client.generated.RestSchema

suspend fun settings() {
    val publishableKey = System.getenv("MOUNTAYA_PUBLISHABLE_KEY").orEmpty()
    val mountaya =
        Mountaya(
            Credential.Publishable(publishableKey, SessionToken.Value(System.getenv("MOUNTAYA_SESSION_TOKEN").orEmpty())),
        )
    // The key names its organization.
    val organization = mountaya.studio.organizations.postOrganizationLookup(RestSchema.OrganizationLookupParams(publishableKey))
    val organizationId = organization.data.id

    val settings = mountaya.admin.organizations.getOrganizationSettings(organizationId)
    println(settings.data.etag)
    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, minted as [mint session tokens](https://docs.mountaya.com/en/sdks/kotlin/admin.md#sessions) shows.

Each sample below takes that client and the organization's id.

- `import com.mountaya.admin.admin` declares the extension `Mountaya.admin: Admin` on the core's client: there is no second client type. It calls through the client's transport, so the credential, the retries, the idempotency keys and the error classes are the client's. Its resources: `billing`, `invitations`, `keys` (publishable keys), `members`, `organizations` (details, settings, usage, AI provider configuration, `postOrganization`), `sessions` (`postSession`), `users` (the acting user's own memberships, preferences and invitations) and `webhooks` (endpoints, events, deliveries, health, event types). Each method is the contract's `operationId`.
- Bodies and answers only the admin unit reaches are printed in `AdminSchema` (`com.mountaya.admin.generated`), naming the core's `RestSchema` types in full.
- 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 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 `users` operations 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 `api` use, and writes nothing: a write answers `401`, refused locally with `ConfigurationException` where a `SessionTokenEngine` reports the token is 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.
- `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/kotlin/admin.md#sessions)); a long-running server hands the client a `SessionTokenEngine` instead. `mountaya.studio.organizations.postOrganizationLookup(OrganizationLookupParams(publishableKey))`, in the core, answers the key's organization (`id`, `name`, `white_label`…), taking the key in its body and no credential.
- An app that draws a map, edits an itinerary, queries the Data API or navigates never declares `mountaya-admin`.

## Members and invitations

```kotlin
import com.mountaya.admin.admin
import com.mountaya.admin.generated.AdminSchema
import com.mountaya.client.Mountaya

suspend fun team(mountaya: Mountaya, organizationId: String) {
    val members = mountaya.admin.members.getOrganizationMembers(organizationId)
    for (member in members.data) println("${member.user_id} ${member.role}")

    mountaya.admin.members.patchOrganizationMember(
        organizationId,
        "7a4e1c98-3b52-4f60-9d81-c05e2f7a83b1",
        AdminSchema.OrganizationMemberUpdateParams(AdminSchema.AssignableOrganizationRole.Viewer),
    )

    mountaya.admin.invitations.postOrganizationInvitation(
        organizationId,
        AdminSchema.OrganizationInvitationCreateParams("camille@example.com", AdminSchema.AssignableOrganizationRole.Contributor),
    )
}
```

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(organizationId) { … }` answers one page of `AdminSchema.OrganizationMember` (`user_id`, `email`, `name`, `role`, `joined_at`), 50 by default. `walkGetOrganizationMembers(organizationId)` walks every page as a cold `Flow` ([pagination](https://docs.mountaya.com/en/sdks/kotlin/pagination.md#paginate)).
- `patchOrganizationMember(organizationId, userId, OrganizationMemberUpdateParams(role))` changes a role; `deleteOrganizationMember(organizationId, userId)` removes a member, or yourself to leave. `role` is an `AdminSchema.AssignableOrganizationRole`: `Admin`, `Contributor` or `Viewer`, and under a key `Contributor` or `Viewer`.
- `postOrganizationInvitation(organizationId, OrganizationInvitationCreateParams(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 `RateLimitException` coded `LIMIT_REACHED`.
- A role the token's user lacks answers `ForbiddenException` (`403`), never `404`.

## API keys

```kotlin
import com.mountaya.admin.admin
import com.mountaya.admin.generated.AdminSchema
import com.mountaya.client.Mountaya

suspend fun websiteKey(mountaya: Mountaya, organizationId: String) {
    val created =
        mountaya.admin.keys.postOrganizationPublishableKey(
            organizationId,
            AdminSchema.PublishableKeyCreateParams(
                "Website",
                listOf(AdminSchema.PublishableKeyScope.Publishing, AdminSchema.PublishableKeyScope.Tiles),
            ),
        )
    // The pk_… value your app sends.
    println(created.data.key)
}
```

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

- `keys` holds `getOrganizationPublishableKeys` (and its walk), `getOrganizationPublishableKey`, `postOrganizationPublishableKey`, `patchOrganizationPublishableKey` (name and scopes, conditional on `ifMatch` with the key's `etag`) and `deleteOrganizationPublishableKey` (revokes it, `revoked_at` set). An `AdminSchema.PublishableKey` carries `id`, `key`, `name`, `scopes`, `etag`, `created_at`, `last_used_at` and `revoked_at`.
- `PublishableKeyCreateParams(name, scopes)`: `scopes` are `AdminSchema.PublishableKeyScope`: `Publishing`, `StudioEmbedded`, `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); `StudioEmbedded` with `Tiles` and `Data`. A scope whose product the organization does not hold 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:

```kotlin
import com.mountaya.admin.admin
import com.mountaya.admin.generated.AdminSchema
import com.mountaya.client.Credential
import com.mountaya.client.Mountaya
import com.mountaya.client.generated.RestSchema
import com.mountaya.client.invoke

// `userId` is the member your own sign-in vouches for, never one read from the request.
suspend fun mint(userId: String): RestSchema.Session {
    val server = Mountaya(Credential.Secret(System.getenv("MOUNTAYA_SECRET_KEY").orEmpty()))
    val session =
        server.admin.sessions.postSession(
            AdminSchema.SessionCreateParams(publishable_key = System.getenv("MOUNTAYA_PUBLISHABLE_KEY").orEmpty()) {
                user_id = userId
            },
        )
    server.close()
    // The token lives minutes.
    println(session.data.expires_at)
    return session.data
}
```

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

- `postSession(SessionCreateParams(publishable_key) { user_id = …; surface = … })` answers the core's `RestSchema.Session` (`token`, `expires_at`, `user_id`). A token lives minutes; `SessionTokenEngine` mints again before it expires.
- A secret key authenticates `postSession` and nothing else: keep one client over `Credential.Secret` for minting, and make every other call through a client over `Credential.Publishable(key, 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 = RestSchema.SessionSurface.StudioEmbedded` mints for Embedded Studio.
- `Credential.Secret` (and `com.mountaya.client.invoke`) is declared on the jvm alone: an Android or iOS build cannot name it.

## Webhook endpoints

```kotlin
import com.mountaya.admin.admin
import com.mountaya.admin.generated.AdminSchema
import com.mountaya.client.Mountaya
import com.mountaya.client.Url

suspend fun subscribe(mountaya: Mountaya, organizationId: String) {
    val endpoint =
        mountaya.admin.webhooks.postOrganizationWebhookEndpoint(
            organizationId,
            AdminSchema.WebhookEndpointCreateParams(
                Url("https://example.com/mountaya/webhooks"),
                listOf("itinerary.published", "organization.member.*"),
            ),
        )
    // whsk_…, shown once: store it now.
    println(endpoint.data.secret)
}
```

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

- `enabled_events` lists event types (`AdminSchema.WebhookEventType` holds each as a constant), families followed by `.*`, or `*` for every public type, later ones included. A type the contract does not publish is a `400` naming its position. The 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 an `AdminSchema.WebhookEndpointWithSecret`: the endpoint and its `secret`, `whsk_` and 64 hexadecimal characters, shown once and never kept for the request's `Idempotency-Key`. No read returns it again; an owner or an admin reveals it in the Mountaya app, where it is rotated too. Its `toString` prints the secret as `<redacted>`.
- `webhooks` also holds `getOrganizationWebhookEndpoints`, `getOrganizationWebhookEndpoint`, `patchOrganizationWebhookEndpoint` (its URL, description, events, and `status` to enable or disable it), `deleteOrganizationWebhookEndpoint`, the events (`getOrganizationWebhookEvents`, `getOrganizationWebhookEvent`), the deliveries (`getOrganizationWebhookDeliveries`, `getOrganizationWebhookDelivery`), `getOrganizationWebhookHealth` and `getWebhookEventTypes`.
- `postOrganizationWebhookDelivery(organizationId, WebhookDeliveryCreateParams(endpointId) { … })` takes exactly one of `event_id` (resend one event), `test = WebhookDeliveryTestParams(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 `RateLimitException` 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/kotlin/webhooks.md): Verify a delivery and handle its event.
- [Authentication in the SDK](https://docs.mountaya.com/en/sdks/kotlin/authentication.md): Session tokens, and acting as a member.
