Provisioning API
An external system (an installer, a billing back office) can set a customer up in Kantoor over HTTPS without the admin screens: attach a domain, create its users and mailboxes, suspend and resume them, read their usage. The API is generic: Kantoor knows nothing about the system that calls it, only about its operator name.
The base path is /api/v1/provisioning. The machine-readable description is the
OpenAPI 3.1 document at /api/v1/provisioning/openapi.json (no key needed; it
describes the API and holds no data).
API keys
A call is authenticated with an operator API key in a Bearer header:
Authorization: Bearer kprov_<prefix>_<secret>A key belongs to an operator, a short lower-case name such as acme. Keys of one
operator share what they provision; a key sees nothing that another operator (or an
admin) created, and asking for it answers 404 as if it did not exist.
| Scope | Allows |
|---|---|
provisioning | reading and writing everything in this guide |
provisioning:read | GET requests only |
There is no scope that reads mail, calendars or contacts, and a key opens nothing outside this API: not the web interface, IMAP, POP3, DAV or the Karta push.
The key is shown once when it is made. Kantoor stores an Argon2id hash of the secret, so it cannot show it again; revoke the key and make another if it is lost.
Making the first key
mix kantoor.api_key.create --name balie --operator balie
# in a release:
bin/kantoor eval 'Kantoor.Release.create_api_key("balie", "balie")'Further keys are made by an admin under Admin, API keys (/admin/api-keys), where
a key can also be revoked and its last use is shown. Creating and revoking are written
to the audit log (never the key). The mix task takes --scope (repeatable) and
--rate-limit.
Limits
Failed authentications are counted per client address: past 30 in a minute every
request from that address, even with a good key, gets 429 for the rest of the
minute. A key may make 600 requests a minute unless it was given another limit. A 429
carries Retry-After.
Errors
Every error, from authentication to validation, is JSON of one shape:
{"error": {"code": "invalid_request", "message": "The request is not valid",
"details": [{"field": "/email", "message": "is invalid"}]}}code is stable and meant for programs; details is present for 422.
| Status | code | Meaning |
|---|---|---|
| 400 | bad_request | the body is not valid JSON |
| 401 | unauthorized | missing, unknown, wrong, revoked or expired key |
| 403 | forbidden | the key's scope does not allow this request |
| 404 | not_found | no such resource, or it belongs to another operator |
| 409 | see each endpoint (ref_conflict, subscription_limit, ...) | the request clashes with the state of something |
| 413 | payload_too_large | the body is too large |
| 422 | invalid_request, unsupported_field, idempotency_key_reuse, invalid_idempotency_key | the request is not valid |
| 429 | rate_limited | see Limits |
| 502, 503 | mail_source_unreachable, mail_source_refused, mail_source_not_configured | the mail source (Karta) could not be used |
Status
GET /api/v1/provisioning/status is what a client polls about the instance:
{"api_version": "1", "version": "1.0.0", "database": "ok",
"sign_in": {"oidc_configured": true}, "vault_configured": true,
"mail_source": {"configured": true, "reachable": true}}mail_source.reachable is the result of a health call to Karta made now; it is null
when Kantoor has no Karta configured. Neither the address nor the key is ever shown.
What Kantoor is, for a provisioning client
Kantoor has no organisation above the mail domain, so the domain is the customer:
its users, mailboxes, seat limit and usage hang on it, and suspending it suspends all
of them. Resources are named by your reference (external_ref, 1 to 128 characters
of letters, digits and . _ : @ -), which is unique per operator; a mailbox is named
by its address.
Kantoor has no local passwords for the web interface: people sign in through the
identity provider (see Sign-in). A user is therefore either created with
the provider's oidc_sub and can sign in at once, or invited: created without it,
and linked by the first sign-in whose email the provider reports as verified
(email_verified: true) and equal to the user's email or to its sign_in_email — the
address the person signs in with when it is not the mailbox address (a customer whose
mailbox is at their own domain and whose account is at the platform's). Nothing else
ever links an account to a person by email. A repeat PUT may still give oidc_sub or
sign_in_email that were unknown at the first call; the user keeps its mailbox
address. IMAP, POP3 and DAV use app passwords the user makes after
signing in; the API does not create or return passwords. Users made through the API are
always plain users: an instance administrator is an admin's decision, and the API
cannot suspend or delete one.
Idempotent writes
Every write can be repeated.
- Natural keys.
PUTon a domain, user or mailbox creates it (201) or, if it is there, returns it unchanged (200). The same reference with different identity (another domain name, another email) is a409 ref_conflict. Settings and profile fields sent with a repeat are ignored; change them withPATCH. Two requests racing for the same reference, on one replica or several, create one resource: the unique index in Postgres decides, and the other gets the existing one. Idempotency-Key. SendIdempotency-Key: <1 to 255 printable characters>with a write and the first answer for that key (per operator) is stored in Postgres for 24 hours. The same key with the same request returns that answer again withIdempotent-Replayed: true; the same key with another method, path or body is422 idempotency_key_reuse. A request that arrives while the first is still running gets409 idempotency_in_progresswithRetry-After. Answers of5xxand429are not stored, so the repeat runs again.- Deletes are idempotent too: deleting what is not there, or is not yours, is
204.
Endpoints
Paths are relative to /api/v1/provisioning. Lists take limit (1 to 500, default
- and
after(thenextof the previous page) and answer{"data": [...], "next": "<cursor or null>"}.
Domains
| Request | Does |
|---|---|
GET /domains | your domains, by name |
PUT /domains/{ref} | create the domain {"name": "example.com", "default_quota_bytes": null, "retention_days": null, "max_users": null} (only name is required; the settings apply on creation) |
GET /domains/{ref} | one domain |
PATCH /domains/{ref} | change the settings that are in the body; null clears one. Raising a quota releases held mail that now fits |
POST /domains/{ref}/suspend | suspend (see below) |
POST /domains/{ref}/resume | resume |
DELETE /domains/{ref} | delete; 409 domain_not_empty while it has users or mailboxes |
POST /domains/{ref}/mail-source | attach to the mail source |
GET /domains/{ref}/usage | counters (see below) |
GET /domains/{ref}/dns-records | the client-discovery DNS records of the domain (read only; see below) |
A domain looks like
{"external_ref": "cust-1", "name": "example.com", "status": "active",
"suspended_at": null, "ingest_enabled": true,
"settings": {"default_quota_bytes": null, "retention_days": null, "max_users": 25},
"mail_source": {"state": "attached", "karta_domain_id": "dom_1",
"signing_secret_stored": true},
"created_at": "..."}Errors: 409 ref_conflict, 409 domain_exists (the name is attached already, to another
operator). A domain an administrator attached by hand has no operator; the API does not claim it
by name alone, but a call with "adopt": true takes it over (the same row, with the mailboxes,
users and mail already on it), so a hand-made set-up can be brought under provisioning without a
duplicate. A user made by hand (no operator) is adopted the same way, by e-mail, with
"adopt": true on PUT /users/{ref}; the row keeps its app passwords, grants and mail.
Attaching the mail source
POST /domains/{ref}/mail-source with an optional
{"karta_domain_id": "...", "api_key": "karta_..."} makes Karta deliver the domain's
mail to Kantoor. Kantoor first calls Karta's health endpoint, so an unreachable Karta is
refused before anything is registered; then it registers the endpoint and route (both
idempotent in Karta) and keeps the endpoint's signing secret encrypted in the vault. It
answers 201 with the domain, or 200 if it was attached already (a different
karta_domain_id is 409 mail_source_conflict). No response ever contains a key, a
secret or Karta's address.
api_key is for a domain that lives in its own Karta organisation (for example one
per customer): the key of that organisation, which Karta can mint through its
provisioning API (kind: "kantoor"). It is kept encrypted on the domain and used for
every call about it: the route, sending from it and fetching its messages. A repeat with
another key replaces it. Without api_key the domain uses the instance key. The key is
never shown again.
Kantoor talks to one Karta address, the one in KARTA_BASE_URL, with the instance
key in KARTA_API_KEY unless a domain brought its own. The address cannot be part of
the call: a body with base_url, endpoint_url, url, credentials or secret is
422 unsupported_field.
Errors: 409 domain_suspended, 409 vault_not_configured (no KANTOOR_VAULT_KEY, so
the signing secret could not be kept), 503 mail_source_not_configured, 502 mail_source_unreachable (health failed), 502 mail_source_refused (Karta refused the
registration; the message carries Karta's error code).
Users
| Request | Does |
|---|---|
GET /users | your users, by email; filters domain_ref, state (active or suspended) |
PUT /users/{ref} | create the user {"domain_ref", "email", "display_name", "locale", "role", "oidc_sub", "sign_in_email"} (domain_ref and email are required) |
GET /users/{ref} | one user |
PATCH /users/{ref} | change display_name and locale (en or nl) |
POST /users/{ref}/suspend | suspend |
POST /users/{ref}/resume | resume a user suspended through the API |
DELETE /users/{ref} | delete the user with its app passwords, grants, identities, calendars, contacts and tasks; mail stays with the mailboxes |
GET /users/{ref}/mailboxes | the mailboxes the user may open |
PUT /users/{ref}/mailboxes/{address} | let the user open a mailbox of its domain |
DELETE /users/{ref}/mailboxes/{address} | take the grant away |
GET /users/{ref}/identities | sending identities |
PUT /users/{ref}/identities/{address} | a sending identity on a mailbox the user may open {"name", "reply_to", "is_default"}; the first becomes the default |
DELETE /users/{ref}/identities/{address} | remove it |
GET /users/{ref}/calendar-subscriptions | the external calendar feeds you set up for the user (see below) |
PUT /users/{ref}/calendar-subscriptions/{sub_ref} | have the user follow a feed {"url", "name", "color", "refresh_minutes", "busy"} |
GET /users/{ref}/calendar-subscriptions/{sub_ref} | one subscription: its host and state, never its address |
PATCH /users/{ref}/calendar-subscriptions/{sub_ref} | change name, color, refresh_minutes, busy, paused or url |
DELETE /users/{ref}/calendar-subscriptions/{sub_ref} | stop following it and delete its events |
The email must be an address at the domain. role is "user" or absent. A user looks like
{"external_ref": "u-1", "email": "ann@example.com", "display_name": "Ann",
"locale": "nl", "role": "user", "domain_ref": "cust-1",
"state": "active", "suspended_by": null,
"sign_in": {"mode": "oidc", "state": "linked"}, "last_login_at": null, ...}suspended_by is operator, domain or admin; sign_in.state is linked or
invited.
Deleting a user deletes its calendar subscriptions with the rest of its calendars.
Errors: 409 user_exists (the email belongs to another user), 409 oidc_sub_taken,
409 seat_limit_reached, 409 domain_suspended, 409 admin_user,
409 disabled_by_admin (resume of a user an admin disabled), 409 user_suspended
(identities of a suspended user), 409 identity_limit, 422 for the fields.
Aliases and the domain's catch-all are not part of this interface: the domain's administrators manage them in Kantoor's domain settings (see Aliases and the catch-all). A mailbox made through this interface gets its own Karta route; an identity is a name on a mailbox address or on an alias of it.
Calendar subscriptions
A subscription makes a user follow a calendar published elsewhere as an iCalendar feed (what other products call a webcal or ICS subscription). The calendar appears in the user's calendar page and in their calendar apps, read-only; see Subscribed calendars. Kantoor knows nothing of whoever publishes the feed: any feed that follows the iCalendar standard works.
PUT /users/u-1/calendar-subscriptions/room-3
{"url": "https://booking.example.com/feeds/3f9c.../rooms/3.ics",
"name": "Room 3", "color": "#1a73e8", "refresh_minutes": 15, "busy": true}| Field | Meaning |
|---|---|
url | required. https:// or webcal:// (rewritten to https), no user name or password, the standard port, at most 2048 characters. Fetched only from public addresses |
name | defaults to the feed's host |
color | #rrggbb |
refresh_minutes | 5 to 10080, default 15 |
busy | whether its events make the user busy for free/busy, default true |
The answer, for PUT (201, or 200 when it exists), GET and PATCH:
{"external_ref": "room-3", "name": "Room 3", "color": "#1a73e8",
"host": "booking.example.com", "refresh_minutes": 15, "busy": true,
"state": "active", "status": "ok",
"last_attempt_at": "...", "last_success_at": "...",
"last_error": null, "error_count": 0, "event_count": 12,
"next_refresh_at": "...", "created_at": "..."}- The address is a secret. The feed's address is often all that protects it. It is
stored encrypted with the vault and never returned: not by
GET, not in a replayedIdempotency-Keyanswer, not in an error, the audit log or the logs (urlis filtered from request logs). The answer carries thehostonly. statusispending(not fetched yet),okorerror. After a failurelast_erroris{"code": "http_404", "message": "..."}, the events from the last good fetch stay, and Kantoor retries with a growing delay;last_success_atsays how old they are. Codes:timeout,too_large,not_public,unresolvable,tls,connect,bad_response,redirects,redirect_loop,redirect_scheme,redirect_invalid,http_<status>,not_calendar,too_many_events,store_failed,vault. A feed whose address does not lead to a public server (not_public) is accepted by the API and then shown with that error; it is never contacted.stateisactiveorpaused(PATCH {"paused": true}stops the automatic refreshes).- Repeats:
PUTwith the same reference and the same feed (inhttps://orwebcal://spelling) is the subscription that exists (200), whatever the other fields say; change them withPATCH. The same reference with another feed is409 ref_conflict.PATCH {"url": ...}gives the same subscription a new address, for a feed whose address was renewed; the next fetch is at once. - The list holds the subscriptions made through the API. A user's own, made in Settings, are not the operator's and are not listed or reachable. Subscriptions of a suspended user are not refreshed until it is resumed.
- No domain-level calendars. A domain in Kantoor is the customer (users, mailboxes), not a holder of calendars, and calendars are shared only between users, so there is no shared or domain calendar to subscribe and no endpoint for one.
Errors: 404 (no such user, or it is another operator's), 409 ref_conflict,
409 subscription_limit (a user has at most 25), 409 user_suspended (only to
subscribe), 409 vault_not_configured (no KANTOOR_VAULT_KEY, so the address could
not be kept), 422 for the fields (/url, /refresh_minutes, /color, /name).
Mailboxes
| Request | Does |
|---|---|
GET /domains/{domain_ref}/mailboxes | the domain's mailboxes, by address, with usage |
PUT /domains/{domain_ref}/mailboxes/{local_part} | create {"quota_bytes": null} with the default folders; null is the domain default |
GET /domains/{domain_ref}/mailboxes/{local_part} | one mailbox |
PATCH /domains/{domain_ref}/mailboxes/{local_part} | set quota_bytes; raising it releases held mail that now fits |
DELETE /domains/{domain_ref}/mailboxes/{local_part} | delete the mailbox, its folders and message index, grants and identities |
Deleting a mailbox asks Karta, in the background and best effort, to forget this
instance's copies of the mail; what Karta still holds is bounded by Karta's own
retention. Creating a mailbox in a suspended domain is 409 domain_suspended.
Usage and status
GET /domains/{ref}/usage and GET /usage (every domain) answer, per domain,
{"domain_ref": "cust-1",
"users": {"total": 12, "active": 11, "suspended": 1},
"seats": {"used": 12, "max": 25},
"mailboxes": {"total": 14, "active": 14},
"storage_bytes": 1234567, "messages": 321,
"held_bytes": 0, "held_messages": 0,
"default_quota_bytes": null, "measured_at": "..."}A seat is a user of the domain, suspended or not; max is the max_users setting,
checked under a lock when a user is created, so concurrent creations cannot exceed it.
storage_bytes is the size of visible mail in the index (what quotas count); mail held
over quota is reported separately. The numbers are computed when asked.
GET /status is described above. Every operation here is synchronous: when a call
returns, the state it describes is true, so polling GET /domains/{ref} or
GET /users/{ref} shows the current state.
Suspension
Suspending is how a customer is switched off without losing anything.
- A user (
POST /users/{ref}/suspend) cannot sign in on the web, with IMAP, POP3 or DAV; open sessions and LiveViews end. App passwords, mail, calendars and contacts stay.resumebrings the user back. - A domain (
POST /domains/{ref}/suspend) does that for every user of the domain, stops ingest for it (mail stays in Karta, whose route is put on hold) and refuses new users and mailboxes.resumebrings back exactly the users the domain disabled and turns ingest on; a user suspended on its own, or disabled by an admin, stays so. The answer'smail_source_syncsays whether Karta's route followed (ok,skippedwhen the domain was never attached,failed: repeat the call). Administrators in the domain are not locked out. A domain suspended this way cannot be enabled in the admin screen; resume it through the API. - What the person sees: the web sign-in answers
403with "This account is suspended. Your mail and data are kept. Contact your administrator or provider to have it restored." IMAP, POP3 and DAV give their ordinary failed-login answer on purpose; they never say why a login failed. - Suspending or resuming twice changes nothing.
A mailbox in a suspended domain that a user of another domain may open stays reachable for that user; suspension acts on users, not on mailboxes.
What a client cannot do
- Give a domain its own Karta (address and key): there is one per instance.
- Set or return passwords, or create app passwords; sign-in is the identity provider's.
- Create aliases or catch-all addresses (the domain's administrators do that in the domain settings), or create administrators, or run a mailbox-less user.
- Rename a domain, change a user's email or domain, or move a mailbox (delete and create).
- Read mail, calendars or contacts, or the audit log. (A calendar subscription reports its state, not its events, and never the feed's address.)
- Delete a domain that still has users or mailboxes, or recover a deleted user's data.
DNS records of a domain
GET /domains/{ref}/dns-records answers the records that let mail, calendar and contact
apps find Kantoor from an address at the domain. It writes nothing; the caller publishes
them. Same authentication and scoping as the other domain calls (another operator's domain
is 404).
{
"domain_ref": "acme",
"name": "acme.example.com",
"records": [
{"purpose": "caldav", "type": "SRV", "name": "_caldavs._tcp.acme.example.com",
"value": "0 1 443 kantoor.example.net.", "ttl": 3600, "required": true,
"note": "CalDAV over TLS: where calendar apps connect."}
],
"unavailable": [],
"zone_file": "_caldavs._tcp.acme.example.com. 3600 IN SRV 0 1 443 kantoor.example.net.\n..."
}Each record has the fields of the records in Karta's domain setup answer (purpose, type,
name, value, required, note) plus ttl; names have no trailing dot, and TXT values
are quoted. records holds only services Kantoor offers, so writing every entry is safe;
the optional RFC 6186 "not available" markers (0 0 0 .) are in unavailable. Types are
SRV, TXT and CNAME; every name and type is one Salt DNS's mail-preset key may update.