Using the Admin API
The Admin API is a JSON-over-HTTP RPC API served by the admin-api Lambda. Every operation is a POST request with a JSON body; there are no GET, PUT, or DELETE routes.
Endpoint URL
Section titled “Endpoint URL”The Admin API is served at https://api.<your mail domain>/admin. The same host serves the User API under /user. The ACM certificate and Route 53 record are created for you during deployment. The host for your deployment is published as the adminApiUrl output — open your stack’s Outputs tab in the CloudFormation console to read it, and append /admin for the Admin API.
Your mail domain is derived from the Route 53 hosted zone you selected when you launched the stack. If you set the optional subdomainNamespace parameter, that label is inserted between the service name and the base domain:
Hosted zone / subdomainNamespace | Admin API endpoint |
|---|---|
example.com, namespace left empty | https://api.example.com/admin |
example.com, namespace mailbox | https://api.mailbox.example.com/admin |
Authentication
Section titled “Authentication”The Admin API requires a Bearer JWT issued by your deployment’s identity provider — the same provider that backs Admin UI sign-in, which is a Cognito user pool unless the deployment configured a different IdP addon. The token must carry the adminApi audience and the ADMIN permission scope.
Machine-to-machine (headless) access
Section titled “Machine-to-machine (headless) access”Provisioning the client (CDK deployments)
Section titled “Provisioning the client (CDK deployments)”Machine-to-machine access requires a deployment built with the ServerlessInbox CDK constructs. A headless app client is not part of a template install — it exists only where the CDK app asks for one explicitly, by calling provisionHeadlessClient({ name, audiences, permissions }) on the MailServerUserPool construct. That call creates a dedicated client_credentials app client and registers it as an accepted audience on the APIs listed in audiences; it returns the client’s ID, its generated client secret as a SecretValue, and the scope strings the client may request.
Where those values go is the deployment’s own choice — the constructs do not store them anywhere. The recommended handling is for the CDK app to put the secret straight into AWS Secrets Manager and never surface it any other way:
const client = userPool.provisionHeadlessClient({ name: 'reporting', audiences: ['adminApi'], permissions: [Permission.ADMIN],});
// clientSecret is set for headless (client_credentials) clients.new secretsmanager.Secret(this, 'ReportingClientSecret', { secretName: 'serverlessinbox/headless/reporting', secretStringValue: client.clientSecret!,});Do not publish the secret as a CfnOutput and do not pass it into a construct property that lands verbatim in the synthesized template: a stack output and a plaintext template value are both readable by anyone with read access to the stack.
The client ID is not a secret and may be published as a stack output or hard-coded in the consumer’s configuration.
Using the client (any consumer)
Section titled “Using the client (any consumer)”The flow itself is standard OAuth 2.0 client_credentials. The client must carry the adminApi audience and the ADMIN permission scope.
Read the secret at run time from Secrets Manager rather than pasting it into the command, and authenticate to the token endpoint with HTTP Basic auth (client_secret_basic) so the secret is never in the POST body:
# 1 — Fetch the client secret at run time; never paste it into the command.CLIENT_ID=<headless-client-id>CLIENT_SECRET=$(aws secretsmanager get-secret-value \ --secret-id serverlessinbox/headless/reporting \ --query SecretString --output text)
# 2 — Obtain a token. --user sends Basic auth, keeping the secret out of the body.# The exact scope string depends on your IDP plugin configuration.# The token endpoint comes from the openid-configuration document; the Cognito form is shown here.TOKEN=$(curl -s -X POST \ --user "$CLIENT_ID:$CLIENT_SECRET" \ "https://<cognito-domain>.auth.<region>.amazoncognito.com/oauth2/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials" \ -d "scope=<admin-scope>" \ | jq -r '.access_token')unset CLIENT_SECRET
# 3 — Use the token in every Admin API callcurl -s -X POST "https://api.mail.example.com/admin/domains/ListDomains" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{}'Never echo, log, or set -x over the secret or the token. Note that a process’s arguments are visible to other users on the host, so --user still exposes the secret on a shared machine — pass it on stdin with curl --config - there, or use an SDK that keeps it in memory.
The access token is short-lived (the identity provider returns its lifetime in expires_in). Cache it in memory and reuse it until it is close to expiry rather than requesting a new token per call.
User-context access
Section titled “User-context access”Admin console UIs use the authorization_code flow. A short-lived access token is obtained via the identity provider’s hosted sign-in UI (the Cognito hosted UI, with the default addon) and sent in the same Authorization: Bearer header.
Authorization
Section titled “Authorization”Every Admin API method requires an admin principal. The caller’s authenticated principal must carry admin privileges (IsAdmin); this applies to all services and methods, including read-only operations. There is no method — not even listing domains or reading the audit log — that a non-admin principal may call.
Webmail mailbox users are issued tokens by the same identity provider, so a token can authenticate successfully yet still belong to a non-admin user. Such a request is authenticated (401 does not apply) but is rejected with HTTP 403 Forbidden on every endpoint.
This is enforced centrally at the request registry, not per handler: a default-deny admin gate runs for every RPC before its handler executes, so an endpoint that omits an explicit check still returns 403 rather than exposing a privileged operation. A method is reachable by a non-admin principal only if it is explicitly allow-listed at registration time, and no method is allow-listed in the current version.
The admin gate runs immediately after the token is authenticated and before the request body is parsed or validated, so an unauthenticated or non-admin caller never receives schema or validation feedback.
Behavioural change. Earlier releases enforced admin access only in a handful of handlers. Operations for domains, suppression, email-identities, audit, mail-feedback, and setup — as well as user reads — were previously reachable by any authenticated (including non-admin) mailbox user. They are now admin-only. Non-admin clients that relied on these endpoints will receive 403 Forbidden.
Request format
Section titled “Request format”Every method call follows the same pattern:
POST /admin/<service>/<MethodName>Authorization: Bearer <token>Content-Type: application/json
{ ...request fields... }The service path and method name map directly to the protobuf service definitions in mail-server-idl/admin-api/proto/. For example, DomainsService.ListDomains is called at:
POST /admin/domains/ListDomainsJSON field names are lowerCamelCase, the same convention used by the push-ws protocol (e.g. stateChange). A proto field defined as domain_id is sent and returned as domainId. Responses are always emitted in camelCase; the server’s JSON decoder is lenient and will also accept the proto’s original snake_case field name, but camelCase is the documented, canonical form and the one used in every example below.
Response format
Section titled “Response format”Successful responses return HTTP 200 with a JSON body containing the response fields defined in the IDL. There is no envelope wrapper — the response is the message directly.
Errors return a non-2xx status code with a JSON body. Every error body has the same shape, and fields that carry no value are omitted:
| Field | Meaning |
|---|---|
code | The error category, written as an enum name such as ERROR_CODE_NOT_FOUND. Branch on this field. |
message | A human-readable description. Its wording is not stable; do not parse it. |
reason | Set on ERROR_CODE_CONFLICT only. Says why the conflict was refused. Branch on this field. |
retryAt | An RFC 3339 timestamp. Set with the ERROR_REASON_COOLDOWN reason, and with ERROR_CODE_RESOURCE_EXHAUSTED when the earliest retry time is known. It is the earliest instant the same request can succeed. |
violations | A list of refused request fields, set on ERROR_CODE_INVALID_ARGUMENT when the fields are known. Each entry has field, the request field’s proto name in snake_case, and description, whose wording is not stable. A violation never carries the submitted value. |
Plain error
Section titled “Plain error”{ "code": "ERROR_CODE_NOT_FOUND", "message": "domain not found"}Conflict with a reason
Section titled “Conflict with a reason”{ "code": "ERROR_CODE_CONFLICT", "message": "mail account limit reached", "reason": "ERROR_REASON_LIMIT_REACHED"}Invalid argument with violations
Section titled “Invalid argument with violations”{ "code": "ERROR_CODE_INVALID_ARGUMENT", "message": "invalid domain: must be a valid domain name", "violations": [ { "field": "domain", "description": "must be a valid domain name" } ]}Error codes and HTTP status
Section titled “Error codes and HTTP status”code | HTTP status | Meaning |
|---|---|---|
ERROR_CODE_INVALID_ARGUMENT | 400 | The request was refused as invalid; see violations |
ERROR_CODE_UNAUTHENTICATED | 401 | Missing or invalid token |
ERROR_CODE_FORBIDDEN | 403 | The token is valid but the principal is not an admin (see Authorization) |
ERROR_CODE_NOT_FOUND | 404 | The requested resource does not exist |
ERROR_CODE_METHOD_NOT_ALLOWED | 405 | The HTTP method is not allowed; every operation is a POST |
ERROR_CODE_CONFLICT | 409 | The request conflicts with the current state; see reason |
ERROR_CODE_UNSUPPORTED_MEDIA_TYPE | 415 | The request’s content type is not supported |
ERROR_CODE_RESOURCE_EXHAUSTED | 429 | A limit is reached; see retryAt |
ERROR_CODE_INTERNAL | 500 | Internal error |
Successful responses return 200.
Conflict reasons
Section titled “Conflict reasons”reason | Meaning |
|---|---|
ERROR_REASON_ALREADY_ACTIVE | An equivalent operation is already in progress |
ERROR_REASON_LIMIT_REACHED | A quota or a rate cap is reached; the called operation says which one |
ERROR_REASON_COOLDOWN | The caller must wait; retryAt says until when |
ERROR_REASON_BUSY | The server is temporarily saturated; retry shortly |
ERROR_REASON_INVALID_STATE | The resource’s current state does not allow the operation |
A conflict with none of these reasons carries no reason field.
Example: verifying the deployment
Section titled “Example: verifying the deployment”StatusService.GetStatus is the smoke-test endpoint — it returns SES sandbox status and Lambda
concurrency hints. Like every Admin API method, it still requires an admin principal (see
Authorization); there is no unauthenticated or reduced-scope health check.
curl -s -X POST "https://api.mail.example.com/admin/status/GetStatus" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{}'Example: provisioning a domain
Section titled “Example: provisioning a domain”# 1 — Register a domainDOMAIN=$(curl -s -X POST "https://api.mail.example.com/admin/domains/AddDomain" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"domain": "acme.com"}')echo $DOMAIN | jq .DOMAIN_ID=$(echo $DOMAIN | jq -r '.domain.id')
# 2 — List the DNS records the domain requirescurl -s -X POST "https://api.mail.example.com/admin/domains/GetDomain" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d "{\"id\": \"$DOMAIN_ID\", \"includeDnsValidation\": true}" | jq .
# 3 — Once DNS is in place, poll GetDomain again until verificationStatus and# dkimStatus are both SUCCESS — there is no separate "verify" call.curl -s -X POST "https://api.mail.example.com/admin/domains/GetDomain" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d "{\"id\": \"$DOMAIN_ID\"}" | jq .Example: creating a user with a mailbox
Section titled “Example: creating a user with a mailbox”There is no CreateUser RPC. A mailbox user is provisioned in two steps: an admin
creates the identity-provider account, and the mailbox itself is created automatically
the first time that person signs in — at which point their receiving address becomes
<username>@<your mail domain> (the email field below is contact metadata only, not
the mailbox address). See Add a user and their mailbox
for the full flow, including what happens on first sign-in and how to confirm the
mailbox now exists:
curl -s -X POST "https://api.mail.example.com/admin/idp-users/CreateIdpUser" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "username": "alice", "email": "alice@acme.com", "password": "<temporary-password>" }' | jq .