Invitations API (B11/B12)
Feature 003 (Organisations, Team & Access), user story 4. Invites a person into an organisation by email, lists/resends/revokes pending invitations, and lets the invitee accept.
:::caution Code-complete, not yet captured against a real deployment
All five routes (lib/routes.ts, packages/api/src/handlers/ invitations.ts/invitation-accept.ts, packages/core/src/repositories/ invitations.ts) are landed and unit-tested as of 2026-10-02. Every
request/response example below is still illustrative — derived from the
schemas and handler source, not a captured execution against a running
dev stack.
:::
Overview
| Op | Method + path (real wire route) | Auth | Idempotency |
|---|---|---|---|
| Create | POST /v1/orgs/{orgId}/invitations | team ≥ MANAGE, or delegated (see below) | Required |
| List | GET /v1/orgs/{orgId}/invitations | team ≥ MANAGE | — |
| Resend | POST /v1/orgs/{orgId}/invitations/{inviteId} (verb :resend embedded in the {inviteId} path value — see Edge cases) | team ≥ MANAGE | None (see Edge cases) |
| Revoke | DELETE /v1/orgs/{orgId}/invitations/{inviteId} | team ≥ MANAGE | — |
| Edit | PATCH /v1/orgs/{orgId}/invitations/{inviteId} | as create | — (versioned) |
| Preview | POST /v1/invitations:preview | Any signed-in caller | None |
| Accept | POST /v1/invitations:accept (the bare POST /v1/invitations is a backward-compatible alias — see Edge cases) | Any signed-in caller — no org context, no team/role check | None |
| Decline | POST /v1/invitations:decline | Any signed-in caller (verified email must match) | None |
| My invitations | GET /v1/me/invitations | Any signed-in caller with a verified email | — |
| Accept / decline mine by id | POST /v1/me/invitations/{inviteId}:accept / :decline | Any signed-in caller (only their own invitations) | None |
| Account check | POST /v1/orgs/{orgId}/account-checks (2026-11-30) | per purpose (see the section) | None |
Resend, revoke and edit are versioned (If-Match/ETag), same mechanism as
Team's PATCH .../members/{sub}. Create, resend and accept are
strict routes (CR-13).
Authentication and authorization
Create/list/resend/revoke all require an {orgId}-scoped caller with
team ≥ MANAGE in that org — same boundary as
Team, driven through the same
requireOrgLevel primitive, so the same role table applies (Super Admin,
Administrator and Business reach it; the Installer template does not). Inviting with the retired Viewer role is
422 VALIDATION_FAILED, details.reason: "ROLE_RETIRED" (field roleId), on create and on PATCH. A Super Admin
skips the escalation check (R-0). The delegated-invite cap (no category above Administrator) now admits the
Business role, because Administrator holds at least every Business level since 2026-11-03.
Installer path (ADR 0021 §3, IO-7.2). A member whose role was minted
from the Installer template may invite End Users into its Business
org without team:
- the role must be the built-in End User (
roleId01M6R61YX1RZXDSYWBKTRYPKKR), else403 FORBIDDENdetails.reason: "INSTALLER_END_USER_ONLY"; - the scope must be
PLANTS, else422 VALIDATION_FAILEDdetails.reason: "INSTALLER_SCOPE_PLANTS_ONLY"; since ADR 0033 (2026-11-27) the target list may be empty, because the End User's own plants join the scope on accept; - every plant must be inside the Installer's own scope or assigned plants,
else
403 FORBIDDENdetails.reason: "INSTALLER_SCOPE"withdetails.invalidTargets; - the escalation check still applies.
Business user (ADR 0033, fixed 2026-11-27). A team ≥ MANAGE member of
the Business (the Business role) may also invite the End User role — the
End User join request. Only email, roleId and scope are needed
(displayName is optional). The scope must be PLANTS (targets may be
empty, or Business plants), else 422 VALIDATION_FAILED
details.reason: "END_USER_SCOPE_PLANTS_ONLY". Before this fix the call was
403 ROLE_NOT_ASSIGNABLE. A member role change to End User is still
refused for a Business user.
The same Installer may resend, revoke and edit only End User invitations it
created itself; any other invitation reads 404. There is no other
role-based allow-list: the level rule (team ≥ MANAGE plus escalation) is
the contract (IO-6). So a Business user with team = MANAGE can still
invite another Business-level member.
End User join request (ADR 0033, 2026-11-27). A Business user or one of its
Installers asks an End User to join by creating an invitation with the End User role. The End User
sees it in GET /v1/me/invitations and gets an INVITATION_RECEIVED inbox item and push whose body
reads "Accepting shares all your plants with Business name. This request expires in 24 hours."
- Consent: nothing changes until
POST /v1/me/invitations/{inviteId}:accept.:declinechanges nothing. - All plants: on accept, every plant of the End User's personal org moves into the Business (ADR 0026 D5). The End User does not pick plants.
- Expiry: 24 hours after create or resend (then
EXPIRED). - One Business: if the invited address belongs to an account (verified or not) already in another Business,
create and resend return
409 CONFLICTdetails.reason: "ALREADY_IN_BUSINESS"(the other Business is not named). Crown staff are refused withdetails.reason: "CROWN_STAFF". An address with no account is checked when it is accepted instead.
Not executed against dev yet (not deployed); the rules above are read from
packages/core/src/repositories/invitations.ts.
Personal orgs (ADR 0021 §5, IO-8) never take a member invitation, from
anyone, Super Admin included: 422 UNSUPPORTED_OPERATION
details.reason: "PERSONAL_ORG" on create, edit and resend. Share
invitations (EXTERNAL, B13) out of a personal org are unaffected.
Delegated invitations (FR-045) are the other exception: a member of an
operator organisation with customers ≥ MANAGE in their own org may
invite someone into a CUSTOMER or PARTNER organisation related to
it (an operator↔customer/partner relationship must already exist — an
unrelated target org is 403 FORBIDDEN), as long as the granted role holds
no category level above Administrator (canDelegateInvite,
packages/core/src/access/policy.ts) — granting, say, a role with
firmware: FULL via a delegated invite is 403 FORBIDDEN details.reason: "ESCALATION". A normal (non-delegated) invite is instead
checked against the FULL FR-031 rule: no category above the caller's OWN
current role, Super Admin exempt (wouldEscalate, same function
Team uses for PATCH .../members/{sub}).
POST /v1/invitations:accept is different in kind: it needs no org
context, team level, or role at all. Authorization IS the email match
(below) — any signed-in Cognito identity may call it, and the response
depends only on whether their account's email matches the invited address.
POST /v1/orgs/{orgId}/invitations
Purpose: Invite a person by email with a role, scope and optional department/display name.
- Side effects: one atomic transaction writes the
INVITEitem, anEMAIL#guard (which doubles as the "already a member or already invited" check — a conditional-write failure on it is the409 ALREADY_EXISTSbelow), and oneMEMBER_INVITEDaccess-log entry. There is no daily invitation limit since RBAC v2 (ADR 0026, 2026-11-13). - Invitation notification: after the transaction, the invitee may get an
INVITATION_RECEIVEDinbox item and web push (only when the address belongs to an account with that email verified). - In-app only, no email (2026-11-17). Invitations are never emailed. The invitee sees pending invitations in the app with
GET /v1/me/invitations(matched by their verified email) and answers withPOST /v1/me/invitations/{inviteId}:acceptor:decline.deliveryis kept in the response for compatibility and is always{ status: "NOT_SENT", attempts: 0 }. acceptUrl: the response returnsacceptUrlonce, only in non-production stages, and only when theINVITE_LINK_BASEenvironment variable is set on the Lambda. It is a client deep link of the form<INVITE_LINK_BASE>#token=<token>: the token is in the URL fragment, which browsers never send to a server, so it cannot reach an access log (audit C2). The client reads the fragment and callsPOST /v1/invitations:acceptwith{ "token": … }. Never returned again on a later list/read.- Where
INVITE_LINK_BASEcomes from (as of 2026-11-03): CDK sets it on the invitations function to<shareLinkBaseUrl>/accept-invite, the web console's accept page, whenever theshareLinkBaseUrlcontext is set (see Operations). Unset, there is noacceptUrl; the invitee still accepts in-app. The variable holds one value per stage; it cannot point at both a deployed console andlocalhost.
Request
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer <token> |
Idempotency-Key | Yes | [A-Za-z0-9_-]{1,128}. Missing → 428 PRECONDITION_REQUIRED with details.header: "Idempotency-Key" — never 400 (CR-7). |
Content-Type | Yes | application/json |
Path parameters: orgId (ULID).
Request body
| Field | Type | Required | Notes |
|---|---|---|---|
email | string | Yes | Normalised server-side (trimmed, lower-cased) before storage/guard use; ≤ 254 chars. |
displayName | string | No | ≤ 120 chars. |
departmentId | ULID | No | Must be a department of this organisation, else 422 VALIDATION_FAILED, message departmentId must be a department of this organisation, details: { field: "departmentId" } |
roleId | ULID | Yes | Subject to the escalation rules above. |
scope | { kind, targets[] } | Yes | Same shape and per-kind target caps as Team's PATCH body (≤10 REGION/TAG/CUSTOMER, ≤500 PLANTS). For an Installer-type role (a custom SCOPED role in a Business org) the value is ignored and NONE is stored (Role boundaries, 2026-11-12). |
Strict (.strict() Zod): an unknown field is 422.
Response
{
inviteId: string; // ULID
status: "PENDING";
expiresAt: string; // +7 days (internal/delegated) or +30 days (external — see Edge cases)
delivery: { status: "NOT_SENT" | "SENT" | "FAILED"; at?: string; attempts: number };
acceptUrl?: string; // non-production stages ONLY, this response only
}
Successful response — illustrative example (dev stage)
{
"inviteId": "01J9Z6A1B2C3D4E5F6G7H8J9K0",
"status": "PENDING",
"expiresAt": "2026-10-09T09:00:00.000Z",
"delivery": { "status": "NOT_SENT", "attempts": 0 },
"acceptUrl": "<INVITE_LINK_BASE>#token=<43-char-base64url>"
}
Failure responses
| Status | code | When | FE action |
|---|---|---|---|
| 401 | — (gateway) | Missing/invalid token | Re-authenticate |
| 403 | FORBIDDEN | Insufficient team/customers level; no relationship to a delegated target org; or details.reason: "ESCALATION" | Don't retry; the caller can't grant this |
| 403 | FORBIDDEN | details.reason: "ROLE_NOT_ASSIGNABLE" — the role cannot be granted in this kind of org (Crown: Super Admin, Administrator, custom roles; Business: custom roles, plus End User on an invitation (Business user, Installer path or Super Admin; ADR 0033) — never on a member role change; customer/personal org: End User only — Role boundaries, 2026-11-12). Also on PATCH …/invitations/{inviteId} | Offer only the roles GET …/roles lists for this org; in a Business org, offer End User on the add-customer / join-request flow |
| 403 | FORBIDDEN | details.reason: "PLATFORM_PERSONAL_ORG" — a personal account opened only through the platform fallback; platform staff cannot create lasting access there (revalidation 2026-11-03) | Don't retry; the action is not available to platform staff here |
| 403 | FORBIDDEN | details.reason: "BUSINESS_ROLE_VIA_CREATE_ONLY" — the Business role in a Business org (2026-11-30, BR-4 / product decision D-3). A Business owner is invited only by POST …/businesses; applies to every caller, Crown staff included. Promoting an existing member (PATCH …/members/{sub}) is unchanged | Don't offer the Business role in the invite drawer |
| 409 | ALREADY_EXISTS | The email is already an ACTIVE/SUSPENDED member or has a PENDING invitation in this org | Show the existing member/invitation instead |
| 409 | CONFLICT | details.reason: "ALREADY_IN_BUSINESS" — the address belongs to an account (verified or not, since 2026-12-01) that already belongs to another live Business; details.reason: "CROWN_STAFF" — the address is Crown staff (target is a Business). Since 2026-11-30 (BR-3) for every role into a Business (Installer-type included), not only End User; also on :resend | Tell the inviter; the person must be removed by the other Business first |
| 422 | VALIDATION_FAILED | Body shape, scope-kind-not-allowed-for-org, invalid scope targets — same reason set as Team's B05 | Depends on reason |
| 422 | UNSUPPORTED_OPERATION | details.reason: "PERSONAL_ORG" — personal orgs never take a member invitation | Pick a Business |
| 428 | PRECONDITION_REQUIRED | Idempotency-Key missing (details.header: "Idempotency-Key") | Generate a key, retry |
| 500 / 503 | INTERNAL / DEPENDENCY_UNAVAILABLE | Server/dependency error | Retry with backoff |
Edge cases
- No daily limit: the 50-invitations/day bucket was removed by RBAC v2 (ADR 0026, deployed to dev 2026-11-13). Create, resend and Business create never answer
429for this reason. - No department: omit
departmentId; the member joins with no department. - Check first: the console checks the invitee with
POST …/account-checkspurpose: "INVITATION"before it creates the invitation. The create still runs every check itself. - Duplicate-email check is a single guard key, not a scan:
EMAIL#<sha256(emailNorm)>under the org, conditionally created by this write and pointing atINVITE#<inviteId>until accept/revoke repoints or frees it. - Expiry: 24 hours for an End User invitation (ADR 0033, see "End User join request" below); otherwise 7 days for an
INTERNALinvite (same org) orDELEGATEDinvite (operator inviting into a related org); 30 days forEXTERNAL(share-by-email — not creatable through this endpoint at all today, see below). EXTERNALinvitations are not created here. The landedcreateInvitationonly ever producesINTERNAL(when the caller's own org equalsorgId) orDELEGATED(when it doesn't, via the FR-045 path) — neverEXTERNAL. Share-by-email (B13) is a separate, not-yet-built code path.- The access-log entry's actor display name is currently the caller's
sub, not a real profile lookup. Same simplification on resend'sINVITATION_RESENTentry. Cosmetic only — doesn't affect authorization or the response body — but don't be surprised to see a sub where a human name is expected in the access log.
GET /v1/orgs/{orgId}/invitations
Purpose: The Invitations tab — every pending/past invitation for the org.
Request
Query parameters
| Name | Required | Type | Notes |
|---|---|---|---|
status | No | PENDING|ACCEPTED|REVOKED|DECLINED|EXPIRED | EXPIRED is derived at read time from expiresAt, never stored. DECLINED (IO-1) is final. |
kind | No | INTERNAL|EXTERNAL|DELEGATED | |
q | No | string, 1–64 chars | 2026-11-25 (console review §4.2, deployed to dev). Any part of the invitee's email (lower-cased; a substring match since 2026-12-01, F8 — crown matches admin1@crowngroup.com) or a prefix of their name (the normalised name the People list sorts by). An accepted, revoked or declined invitation has dropped the name index, so only its email matches. |
roleId | No | ULID | 2026-11-25. Only invitations on this role. |
departmentId | No | ULID | 2026-11-25. Only invitations into this department. |
limit | No | integer 1–50; default 15 on the first page, 10 with a cursor (lazy loading) |
Response
{
items: Array<{
inviteId: string;
kind: "INTERNAL" | "EXTERNAL" | "DELEGATED";
emailMasked: string; // always masked — this list is team >= MANAGE only, no unmasked tier
displayName?: string;
role?: { roleId: string; name: string };
status: "PENDING" | "ACCEPTED" | "REVOKED" | "DECLINED" | "EXPIRED";
expiresAt: string;
delivery: { status: "NOT_SENT" | "SENT" | "FAILED"; at?: string; attempts: number };
sendCount: number; // 1 on create, +1 per resend
invitedBy: string; // NOTE: currently a bare identifier (sub), not {sub, displayName} — see Edge cases
version: number; // N-45: always present; the If-Match value for resend / revoke / PATCH
}>;
// no nextCursor today — see Edge cases
}
Failure responses
| Status | code | When |
|---|---|---|
| 401 | — (gateway) | Missing/invalid token |
| 403 | FORBIDDEN | team < MANAGE |
| 500 / 503 | INTERNAL / DEPENDENCY_UNAVAILABLE | Server/dependency error |
Edge cases
- No pagination yet. The landed
listInvitationsruns one boundedQuerycapped atlimitwith no cursor support — there is nonextCursorfield at all today, unlike every other list endpoint in this API. Documented limitation (same shape Team'sq-search path uses), not a bug — a follow-up once an org has enough invitations for it to matter. invitedByis a bare string (the inviter'ssub), not the{sub, displayName}object the contract originally sketched — resolve a display name client-side via the People list if needed.emailMaskedhere has no unmasked tier (unlike Team's People list atteam≥ MANAGE) — this whole route is alreadyteam≥ MANAGE only, so masking is applied unconditionally.
POST /v1/orgs/{orgId}/invitations/{inviteId}:resend
Purpose: Rotates the token (old one dies immediately), resets the
expiry clock, and increments sendCount.
:::info Real wire route has no :resend in the URL template (CR-2)
API Gateway can't register a path template containing a literal : segment,
so the deployed route is POST /v1/orgs/{orgId}/invitations/{inviteId} —
the SAME path+method as every other {inviteId} request. The verb travels
as part of the path parameter's VALUE: send the request to
POST /v1/orgs/{orgId}/invitations/<inviteId>:resend literally (colon and
all, in the URL), and the server splits <inviteId>:resend on the first
colon (parseActionSegment) before anything else runs. An unknown or
missing verb (e.g. hitting the bare {inviteId} with POST and no verb at
all) is 404 NOT_FOUND, same as any unmatched route — not a 400.
:::
- Side effects: one transaction overwrites
tokenHash/the GSI1 token-lookup attrs/expiresAt/delivery(reset toNOT_SENT) and bumpssendCount, plus oneINVITATION_RESENTaccess-log entry. No rate limit (removed by RBAC v2, ADR 0026). The web console labels this action "Renew invitation" — for an in-app invitation its effect is the new expiry. - Invitation notification: a renewal writes a NEW
INVITATION_RECEIVEDitem for the invitee (when they have an account with that email verified) and marks the previous one read.
Request
Headers: If-Match required (a stale value is 409 VERSION_CONFLICT,
missing is 428, malformed is 400 — same as
Team's PATCH).
No Idempotency-Key behavior — despite the original spec contract
listing it as optional, it is not wired through the idempotency mechanism
for this route today (lib/routes.ts's idempotency: 'none'); a resend has
no create-time duplicate-request hazard, only token rotation, so this was a
deliberate simplification, not an oversight. Path: orgId, inviteId
(ULID — the real request sends <inviteId>:resend as its value, see above).
Response
Same shape as create above, with a NEW
expiresAt/acceptUrl and the old token no longer resolving to anything
(its GSI1 entry is overwritten, not merely marked dead — a lookup against
it behaves exactly like an unknown token).
Failure responses
| Status | code | When |
|---|---|---|
| 401 | — (gateway) | Missing/invalid token |
| 403 | FORBIDDEN | team < MANAGE |
| 404 | NOT_FOUND | inviteId doesn't exist in this org |
| 409 | VERSION_CONFLICT / INVALID_STATE | Stale If-Match, or the invitation is not PENDING (already accepted/revoked/concurrently resent) |
| 428 | PRECONDITION_REQUIRED | If-Match missing |
| 500 / 503 | INTERNAL / DEPENDENCY_UNAVAILABLE | Server/dependency error |
DELETE /v1/orgs/{orgId}/invitations/{inviteId}
Purpose: Revoke a pending invitation.
- Side effects: one transaction sets
status: REVOKED(revokedAt/revokedByrecorded) and deletes theEMAIL#guard, freeing the address to be re-invited immediately — plus oneINVITATION_REVOKEDaccess-log entry. The record is kept, never deleted.
Request
Headers: If-Match required. Path: orgId, inviteId.
Response
204 No Content.
Failure responses
| Status | code | When |
|---|---|---|
| 401 | — (gateway) | Missing/invalid token |
| 403 | FORBIDDEN | team < MANAGE |
| 404 | NOT_FOUND | inviteId doesn't exist in this org |
| 409 | INVALID_STATE | Already accepted or revoked |
| 428 | PRECONDITION_REQUIRED | If-Match missing |
| 500 / 503 | INTERNAL / DEPENDENCY_UNAVAILABLE | Server/dependency error |
PATCH /v1/orgs/{orgId}/invitations/{inviteId}
Edit the role, scope and/or department of a pending invitation (N-47).
Handler patchInvitation in packages/api/src/handlers/invitations.ts, core
patchInvitation in packages/core/src/repositories/invitations.ts. No
execution captured; examples are illustrative.
- AuthZ: same as create —
team≥ MANAGE on{orgId}, or the delegated operator path (FR-045), which may edit only invitations its own org sent (others →404). - Headers:
Authorization,X-Org-Id,If-Match(required: missing →428, stale →409 VERSION_CONFLICT). NoIdempotency-Key— the version guards replays. - Body (strict, at least one field):
| Field | Type | Notes |
|---|---|---|
roleId | ULID | Same role checks as create |
scope | Scope | Same scope checks as create. With an Installer-type role, a role or scope edit stores NONE; a department-only edit keeps the stored scope (2026-11-12) |
departmentId | ULID | null | null clears the department (no check). A ULID must be a department of this organisation, else 422 VALIDATION_FAILED with details: { field: "departmentId" } |
// illustrative example
{ "roleId": "01JB7R0000000000000000000R", "departmentId": null }
Response 200 + ETag:
{ inviteId: string; kind: "INTERNAL" | "DELEGATED"; status: "PENDING"; roleId: string; scope: Scope;
departmentId?: string; expiresAt: string; version: number }
Writes an access-log entry of type INVITATION_UPDATED.
| Status | code | When |
|---|---|---|
| 401 | — (gateway) | Missing/invalid token |
| 403 | FORBIDDEN | Not allowed to invite here; or details.reason: "ESCALATION" — the new role/scope grants more than the caller holds (delegated: more than Administrator) |
| 403 | FORBIDDEN | details.reason: "PLATFORM_PERSONAL_ORG" — personal account reached only through the platform fallback |
| 403 | FORBIDDEN | details.reason: "BUSINESS_ROLE_VIA_CREATE_ONLY" — changing the role to Business (2026-11-30, BR-4). The owner invitation that POST …/businesses created keeps its Business role through a scope or department edit |
| 404 | NOT_FOUND | Unknown invitation, another org's invitation on the delegated path, or unknown role |
| 409 | INVALID_STATE | Not pending (accepted/revoked/expired), or an EXTERNAL (share) invitation — change the share instead |
| 409 | VERSION_CONFLICT | Stale If-Match |
| 422 | VALIDATION_FAILED | Empty body, unknown field, bad scope for the role/org |
| 428 | PRECONDITION_REQUIRED | No If-Match |
POST /v1/invitations:preview
Read-only look at an invitation before deciding (N-42, IO-2). Served by
POST /v1/{collection} (packages/api/src/handlers/plants-write.ts → preview
in invitation-accept.ts). No execution captured; examples are
illustrative.
- Auth: any signed-in caller. No
X-Org-Id, noIdempotency-Key. - Body (strict):
{ "token": "<43 base64url chars>" }— the token from the invite link, never in the URL. - A live token (PENDING, not expired) previews for anyone holding it, with
status: "PENDING". So a person signed in with another account still sees which Business invited them, andinvitedEmailMaskedtells them which account to use. - A used token (accepted, declined, revoked, expired) previews with its
real
statusonly when the caller's verified email is the invited one. Anyone else, and any unknown or resent-away token, gets the same uniform404, so the endpoint can't be used to probe. scopeis a display-only summary, the sametargetsLabelas the member scope summary. It isnullfor a share invitation.- Invitations are never emailed (2026-11-17). A resend rotates the token, so an earlier
acceptUrlstops working; the in-app list is unaffected.
Response 200:
// illustrative example — derived from the schema, not a captured execution
{ "kind": "INTERNAL", "org": { "name": "Sunrise Solar" }, "role": { "name": "End User" },
"scope": { "kind": "PLANTS", "targetsLabel": "2 plants" },
"inviter": { "displayName": "Ayesha K." }, "invitedEmailMasked": "a***@example.com",
"expiresAt": "2026-11-13T10:00:00.000Z", "status": "PENDING" }
role, scope and inviter may be null. status is one of PENDING,
ACCEPTED, DECLINED, REVOKED, EXPIRED.
| Status | code | When |
|---|---|---|
| 401 | — / UNAUTHENTICATED | Not signed in |
| 404 | NOT_FOUND | Unknown or resent-away token, or a used token previewed by anyone but the invitee |
| 422 | VALIDATION_FAILED | Missing/malformed token or extra fields |
| 429 | RATE_LIMITED | More than 30 previews per minute per caller (Retry-After) |
POST /v1/invitations:decline
The invitee declines (IO-1, ADR 0021 §1). Served by POST /v1/{collection}
(plants-write.ts → decline in invitation-accept.ts). Not yet executed
against dev.
- Auth: any signed-in caller, no
X-Org-Id, noIdempotency-Key(a repeat is409). Body (strict){ "token": "…" }, never in a URL. - Checks, in the same order as accept:
404unknown or resent-away token;409 INVALID_STATEno longerPENDING;410 GONEexpired;403 FORBIDDENthe account's verified email is not the invited one (or is unverified), with the invitation leftPENDING. - Side effects (one transaction):
- the invitation becomes
DECLINED(declinedAt,declinedBy) and leaves the People list; - the
EMAIL#guard and the invitee inbox entry are deleted, so the inviter can send a new invitation; - one
INVITATION_DECLINEDaccess-log entry is written in the inviting org.
- the invitation becomes
DECLINEDis final: accept, resend or revoke afterwards is409.- Decline never creates or changes a membership, the Cognito account or the personal org.
- A share invitation (
kind: EXTERNAL) is not declined here:422 UNSUPPORTED_OPERATION,details.reason: "SHARE_INVITATION".
// illustrative 200
{ "inviteId": "01JC…", "status": "DECLINED", "org": { "name": "Sunrise Solar" } }
GET /v1/me/invitations
The caller's own PENDING, unexpired INTERNAL/DELEGATED invitations,
addressed to their verified email, newest first (IO-4, ADR 0021 §6). It
lets a person who signed in without the link (lost email, another device)
still find and decide their invitations.
- Auth: any signed-in caller. No verified email →
403 FORBIDDEN. - Query:
limit(1–50; default 15 on the first page, 10 with acursor(lazy loading)) andcursoronly. - Reads the invitee inbox (
INVITEE#<sha256(email)>, one Query), then re-checks each invitation. Never returns a token. - An invitation created before this route existed appears once it is
resent (
:resendwrites the inbox entry).
// illustrative 200
{ "items": [ { "inviteId": "01JC…", "kind": "INTERNAL",
"org": { "orgId": "01JB…", "name": "Sunrise Solar" }, "role": { "name": "End User" },
"scope": { "kind": "PLANTS", "targetsLabel": "2 plants" },
"inviter": { "displayName": "Ayesha K." }, "expiresAt": "2026-11-13T10:00:00.000Z", "status": "PENDING" } ] }
Invitation notification (INVITATION_RECEIVED)
Added and deployed to dev 2026-11-23 (web console request R1). Since invitations are in-app only, the invitee is told through the
HTTP inbox (GET /v1/me/notifications) and a web push.
When: right after an INTERNAL or DELEGATED invitation is created
(POST …/invitations, or a Business owner's invitation from
POST …/businesses) or renewed (:resend).
Share invitations (EXTERNAL) get none.
Who: the one account whose email is the invited address and is verified (one Cognito ListUsers per
create or renewal). No account, an unverified email, or more than one account with that email → no item; the person
sees the invitation in GET /v1/me/invitations once they sign up and verify the address
(KI-28). An admin inviting their own address gets nothing.
Item (illustrative, derived from the code — not a captured execution):
{
"notificationId": "01JD…",
"kind": "INVITATION_RECEIVED",
"title": "You're invited to join Sunrise Solar",
"body": "Role: End User",
"link": { "type": "INVITATION", "id": "01JC…" },
"actor": { "displayName": "Ayesha K." },
"invitation": { "inviteId": "01JC…", "org": { "orgId": "01JB…", "name": "Sunrise Solar" }, "role": { "name": "End User" } },
"createdAt": "2026-11-23T10:00:00.000Z"
}
linkhas noorgId— the invitee is not a member yet. Accept or decline withPOST /v1/me/invitations/{inviteId}:accept|:decline.invitation.org/invitation.roleare the names when the invitation was sent;roleisnullif the role could not be read.actoris the inviter's display name when their profile has one.- Web push: same transaction as the item, under the normal push rules (Notifications):
link: "/",tag: "invite-<inviteId>",data.inviteId. Web endpoints exist only for End Users, so staff invitees get the inbox item only. - Lifecycle: accepting, declining or revoking the invitation marks the item read; a renewal adds a new item and
marks the old one read. The item's TTL is the invitation's
expiresAt, so it leaves the list when the invitation expires (the unread count may over-count briefly until the next full list repairs it). - Best-effort: the invitation write never fails because of the notice. A failure is logged
(
invitation_notice_failed, no email or sub in the log) and the invitation still shows inGET /v1/me/invitations. - Small race: if the invitee accepts in the instant between the item's write and storing its address, the item may stay unread until the invitation's expiry hides it.
POST /v1/me/invitations/{inviteId}:accept|:decline
Accept or decline one of your own invitations by id, with no token needed
(IO-4). The invitation is found only through your verified email's inbox, so
someone else's id is 404. Same checks, transaction, access-log entry and
response as the token routes. No body (422 if one is sent), no
Idempotency-Key. Real wire route: POST /v1/me/invitations/{inviteId}
with <inviteId>:accept as the path value (CR-2).
POST /v1/invitations:accept
Purpose: The invitee accepts — attaches the invitation to their signed-in account.
:::info POST /v1/invitations:accept is callable; the bare POST /v1/invitations is an alias
API Gateway matches POST /v1/invitations:accept to the catch-all
POST /v1/{collection} route, whose handler dispatches invitations:accept
to this operation (audit C1, live from the next deploy). The bare
POST /v1/invitations serves the same operation and stays for backward
compatibility. Neither takes an Idempotency-Key. Two further points:
-
No
{token}path parameter, ever. The blueprint originally sketchedPOST /v1/invitations/{token}:accept(token as a path segment). This spec's own deviation D-09 supersedes that: the token travels in the request body instead ({ "token": "…" }), specifically so it never appears in a URL, CloudFront access log, or browser history (07-security.md §5 logging hygiene). -
No
{id}at all for the action route itself (CR-2). Unlike resend (which has a real{inviteId}to hang the verb off), accept has no id — the verb is the wholeinvitations:acceptsegment. ::: -
Authentication: Required — any signed-in Cognito identity. No org context, no
team/role check at all. MFA is not required to accept (an org's own MFA requirement applies starting with the next request IN that org, not to this call). -
Side effects (internal/delegated): one transaction marks the invitation
ACCEPTED, creates (or reactivates, see Edge cases) theMEMBERitem, repoints theEMAIL#guard fromINVITE#<id>toMEMBER#<sub>, and writes oneINVITATION_ACCEPTEDaccess-log entry in the inviting org. -
External invitations are not acceptable through this endpoint today. The landed
acceptInvitationfails closed with422 UNSUPPORTED_OPERATIONforkind: "EXTERNAL"rather than silently no-op'ing — that flow (share/portal activation, B13) isn't built yet.
Request
Headers: Authorization: Bearer <token> only — no X-Org-Id.
Request body
| Field | Type | Required | Notes |
|---|---|---|---|
token | string | Yes | Exactly 43 characters, base64url (^[A-Za-z0-9_-]{43}$) — 32 raw bytes. Single-use. |
Response
{
orgId: string;
kind: "INTERNAL" | "EXTERNAL" | "DELEGATED";
membership?: MembershipSummary; // internal/delegated accept
share?: { shareId: string; level: string; operatorOrgName: string }; // external accept (not reachable yet — see above)
}
Failure responses
| Status | code | When | FE action |
|---|---|---|---|
| 401 | — (gateway) | Missing/invalid token | Re-authenticate |
| 403 | FORBIDDEN | The signed-in account's email doesn't match the invited email (case-insensitive) | Sign in with the right account; the invitation is untouched and still acceptable by it (X12) |
| 404 | NOT_FOUND | Unknown token — a constant-time GSI1 hash lookup finds nothing. Deliberately the SAME shape as any other invalid-token case, so a client can't distinguish "wrong token" from "right token, wrong account" by response shape | Show a generic "this invitation link isn't valid" message |
| 409 | INVALID_STATE | Already ACCEPTED, DECLINED or REVOKED | Don't retry |
| 410 | GONE | expiresAt has passed | Ask the inviter to resend |
| 422 | UNSUPPORTED_OPERATION | kind: "EXTERNAL" — not acceptable here yet | n/a (shouldn't be reachable from a real share-by-email link yet) |
| 422 | LIMIT_EXCEEDED | Accepting would put the account over the 50-membership cap | Leave another organisation first |
| 500 / 503 | INTERNAL / DEPENDENCY_UNAVAILABLE | Server/dependency error | Retry with backoff |
Edge cases
- Concurrent accepts of the same token: the invitation-status
conditional update (
PENDING→ACCEPTED) ensures exactly one of two simultaneous accept attempts wins; the loser seesINVALID_STATE(or, rarely,NOT_FOUNDif the GSI1 projection hadn't caught up to the winner's write yet). - Existing account, never re-created (X13): if the invited email's
accepting
subalready has a (e.g.REMOVED) membership row in the target org, that row is reused in place — theMEMBERwrite's own condition is "not exists OR status REMOVED", never a blind overwrite of an ACTIVE row. - Email match is case-insensitive and compares against
IdentityProvider.getUserContact(sub)'s verified account email — not a client-supplied value. - 50-membership cap is enforced on write, not only on read — a 51st
accept is refused rather than silently exceeding the cap enforced
elsewhere (
access/loader.ts's own read-sideMAX_MEMBERSHIPS).
POST /v1/orgs/{orgId}/account-checks
Purpose (2026-11-30, BR-1): one read-only email → account check for the web console's three flows — Share
Plant (PLANT_TRANSFER), Create Business (BUSINESS_OWNER) and the invite drawer (INVITATION). It
answers who the email belongs to and whether the matching create / transfer would accept them. It replaces
plant-transfer-checks, which
stays as an alias of purpose: "PLANT_TRANSFER" until the console has moved, then is retired.
Code: handler checkAccountRecipient (packages/api/src/handlers/invitations.ts), core
packages/core/src/access/account-check.ts (BUSINESS_OWNER, INVITATION) and plants/transfer-check.ts
(PLANT_TRANSFER). Built on dev 2026-11-30; not deployed and no request captured yet — the examples below are
illustrative, derived from AccountCheckResponse in schemas.ts.
Headers: Authorization: Bearer <token>, Content-Type: application/json. No If-Match, no
Idempotency-Key. Nothing is written except the caller's rate-limit counter.
Body (strict JSON — the email stays out of URLs and access logs)
| Field | Type | PLANT_TRANSFER | BUSINESS_OWNER | INVITATION |
|---|---|---|---|---|
purpose | PLANT_TRANSFER | BUSINESS_OWNER | INVITATION | required | required | required |
email | string | required | required | required — trimmed, lower-cased, ≤ 254 |
plantId | ULID | required | 422 if sent | 422 if sent |
businessOrgId | ULID | optional, Crown staff (as today) | 422 if sent | optional — the target Business, Crown staff only (anyone else: 422); absent = {orgId} |
roleId | ULID | 422 if sent | 422 if sent | required — the role the invitation would grant |
Authorization (thrown before the email is read)
A caller who could not do the real action gets an error, never eligible: false, and learns nothing about the email.
- PLANT_TRANSFER — exactly
plant-transfer-checks: the transfer's caller, mode and plant checks. - BUSINESS_OWNER —
{orgId}must be the Crown PLATFORM org (409 INVALID_STATEotherwise);customers≥ MANAGE andteam≥ MANAGE there, as onPOST …/businesses. - INVITATION — the caller could create this invitation in the target org: the same caller resolution as
POST …/invitations(team≥ MANAGE; Crown staff through the platform fallback whenbusinessOrgIdis sent; the Installer path), then the role checks:422 PERSONAL_ORG,403 SUPER_ADMIN_ONLY,403 ROLE_NOT_ASSIGNABLE,403 INSTALLER_END_USER_ONLY,403 BUSINESS_ROLE_VIA_CREATE_ONLY,403 ESCALATION,404unknown role. AbusinessOrgIdthat does not exist is404; one that is not a Business is422NOT_A_BUSINESS. BUSINESS_OWNER and INVITATION never read a plant.
Eligibility (200, eligible: false + reason)
reason | PLANT_TRANSFER | BUSINESS_OWNER | INVITATION |
|---|---|---|---|
USER_NOT_REGISTERED (found: false, no recipient) | as before | ✔ | ✔ |
ACCOUNT_BLOCKED | as before | ✔ | ✔ |
MOVE_IN_PROGRESS (the person's plants are being moved; not resumed by the check) | as before | ✔ | ✔ |
USER_IN_ANOTHER_ORG, NOT_AN_END_USER, ALREADY_OWNER, LIMIT_EXCEEDED, MEMBER_NOT_ACTIVE | as before | — | — |
CROWN_STAFF (new) — active Crown membership | — | ✔ | ✔ when the target is a Business |
ALREADY_MEMBER (new) — active or suspended member of the target org (a REMOVED member may be invited again) | — | — | ✔ |
ALREADY_IN_BUSINESS — member or owner (any role, suspended included) of a live Business; a CLOSED one does not count | — | ✔ | ✔ when the target is a Business and it is another Business |
INVITATION_PENDING | as before | a pending Business-owner invitation anywhere | a pending invitation to the target org |
The checks run in this order: blocked, move in progress, then (BUSINESS_OWNER) Crown staff, other Business, pending owner invitation — or (INVITATION) already a member, Crown staff, other Business, pending invitation. The first match is returned.
Rate limit: one per-caller bucket shared by every purpose and plant-transfer-checks: 20 checks per minute and
200 per day → 429 RATE_LIMITED with Retry-After.
Privacy: recipient has only the display name (null when none is set) and the normalised email you typed — no
sub, org id or name, or phone. message never names another Business.
Not a guarantee: the create or transfer re-checks everything; handle its errors as before.
Response 200
{
found: boolean;
recipient?: { displayName: string | null; email: string }; // only when found
eligible: boolean;
reason: AccountCheckReason | null; // null when eligible
message: string | null; // null when eligible; safe to show as is
}
Illustrative examples (derived from the schema, not captured executions)
// POST /v1/orgs/<platformOrgId>/account-checks
{ "purpose": "BUSINESS_OWNER", "email": "owner@example.com" }
// 200 — the owner already belongs to a Business
{
"found": true,
"recipient": { "displayName": "Ali Khan", "email": "owner@example.com" },
"eligible": false,
"reason": "ALREADY_IN_BUSINESS",
"message": "This person already belongs to a business. They can own a new business only after that business removes them."
}
// POST /v1/orgs/<platformOrgId>/account-checks — Crown staff, invite drawer for Business X
{ "purpose": "INVITATION", "email": "installer@example.com", "roleId": "<Business X Installer role id>", "businessOrgId": "<Business X id>" }
// 200
{ "found": true, "recipient": { "displayName": null, "email": "installer@example.com" }, "eligible": true, "reason": null, "message": null }
Failure responses
| Status | code | When |
|---|---|---|
| 400 | MALFORMED_REQUEST | Body is not JSON |
| 401 | (gateway) | Missing or invalid token |
| 403 | FORBIDDEN | The caller may not do the real action (see Authorization; details.reason where one applies) |
| 404 | NOT_FOUND | No membership in {orgId} (or the picked Business); plant, role or picked Business not found |
| 409 | INVALID_STATE / CONFLICT | PLANT_TRANSFER plant-side refusals; BUSINESS_OWNER with a non-PLATFORM {orgId} |
| 422 | VALIDATION_FAILED | Strict body; a field the purpose does not take or a missing required one; businessOrgId from a non-staff caller; NOT_A_BUSINESS |
| 422 | UNSUPPORTED_OPERATION | details.reason: "PERSONAL_ORG" (INVITATION into a personal org) |
| 429 | RATE_LIMITED | Over 20/minute or 200/day for this caller (Retry-After) |
Edge cases
- Check vs create agree (since 2026-12-01): both resolve any account with the email, verified or not, and the
create refuses
ALREADY_IN_BUSINESSandCROWN_STAFFexactly as the check reports them. - Create Business race: the owner check runs just before the create, not inside its transaction; an owner who joins another Business in between is refused when they accept the owner invitation.
POST /v1/orgs/{orgId}/businesses
Purpose: create a Business (an OPERATOR organisation) and invite its owner on the built-in
BUSINESS role, in one call (ADR 0014; built 2026-11-02). Used by the web admin console's
"Business Management" screen. Nothing on this route has been run against a deployed stage yet.
Authentication: Cognito ID token from the web-console app client, Authorization: Bearer <token>.
Authorization
{orgId}must be the Crown PLATFORM organisation. Any other org:409 INVALID_STATE.- The caller needs
customers≥ MANAGE andteam≥ MANAGE in that PLATFORM org (Super Admin and Administrator by default;teamadded 2026-11-03 because the route invites the owner). Below that:403 FORBIDDEN. - A caller with no ACTIVE membership in
{orgId}:404 NOT_FOUND. - Since 2026-11-03 (R-3b) creating a Business is an ordinary grant: a caller who is not Super Admin must hold at
least every level of the (effective) Business role, lowered by
permsLimitif one is sent, and everypermsLimitvalue. Otherwise403 FORBIDDEN,details.reason: "ESCALATION". Administrator passes by default (it holds at least every Business level). A Super Admin is never refused.
Side effects (one DynamoDB transaction; a failure leaves nothing behind):
- the new OPERATOR org, including its five seeded role templates (Installer among them);
- a
DELEGATEDinvitation forowner.emailin the new org, roleBUSINESS, scopeALL, expiring in 7 days; - an
ORG_CREATEDaccess-log entry in both the new org and the PLATFORM org; - with
permsLimit: the Business limit (version 1) andBUSINESS_LIMIT_CHANGEDin both access logs.
Owner must be an existing, eligible account (2026-11-30, BR-2). Before anything is written, owner.email is
resolved to its account (Cognito, by email) and checked with the BUSINESS_OWNER rules of
POST …/account-checks. A refusal creates nothing — no org, no invitation — and
error.details.reason names the rule (see the failure table). Request and response bodies are unchanged. The check
is a read before the write, not part of the transaction: if the owner joins another Business in between, the
invitation is still created and the accept-time one-Business rule refuses it.
There is no daily invitation budget since RBAC v2 (ADR 0026, 2026-11-13). No email is sent: the owner finds the
invitation in-app (GET /v1/me/invitations) and, when the address belongs to an account with that email verified,
gets an INVITATION_RECEIVED inbox item and web push.
invitation.delivery is always NOT_SENT.
Request
Headers
| Header | Required | Value |
|---|---|---|
Authorization | Yes | Bearer <token> |
Idempotency-Key | Yes | [A-Za-z0-9_-]{1,128}. Missing: 428 PRECONDITION_REQUIRED. |
Content-Type | Yes | application/json |
Path parameters: orgId (ULID of the PLATFORM org).
Request body (strict: an unknown field is 422)
| Field | Type | Required | Notes |
|---|---|---|---|
name | string | Yes | Trimmed, 1 to 120 chars. |
countryCode | string | Yes | ISO 3166-1 alpha-2, upper-cased server-side. |
timezone | string | Yes | IANA zone, at most 64 chars, e.g. Asia/Karachi. |
locale | string | No | BCP 47, 2 to 35 chars. Default en-PK. |
currency | string | No | ISO 4217, upper-cased. Default PKR. |
contact | OrgContact | No | Same shape as the org profile's contact (legalName, businessType, address, phone, ...; each at most 200 chars). |
owner.email | string | Yes | Trimmed and lower-cased; at most 254 chars. |
owner.displayName | string | No | At most 120 chars. |
permsLimit | PermsLimit or null | No | Since 2026-11-03. The Business limit to start with; null or {} = none. |
Response: 201 Created
{
org: Organisation; // the new OPERATOR org, same shape as GET /v1/orgs/{orgId}
invitation: {
inviteId: string; // ULID
roleId: string; // the BUSINESS system role id
status: "PENDING";
expiresAt: string; // +7 days
delivery: { status: string; attempts: number };
acceptUrl?: string; // non-production stages only, this response only
};
}
Illustrative example (derived from the schema, not a captured execution)
{
"org": { "orgId": "01JBZ0000000000000000000AA", "kind": "OPERATOR", "name": "Sunrise Solar", "...": "..." },
"invitation": {
"inviteId": "01JBZ0000000000000000000BB",
"roleId": "<BUSINESS role id>",
"status": "PENDING",
"expiresAt": "2026-11-09T09:00:00.000Z",
"delivery": { "status": "NOT_SENT", "attempts": 0 },
"acceptUrl": "<INVITE_LINK_BASE>#token=<token>"
}
}
Failure responses
| Status | code | When | FE action |
|---|---|---|---|
| 400 | MALFORMED_REQUEST | Body is not valid JSON | Fix the client |
| 401 | (gateway) | Missing or invalid token | Re-authenticate |
| 403 | FORBIDDEN | customers or team below MANAGE in the PLATFORM org; or details.reason: "ESCALATION" (R-3b, above) | Hide the action |
| 403 | FORBIDDEN | details.reason: "ACCOUNT_BLOCKED" — the owner's account is blocked (BR-2) | Pick another owner |
| 404 | NOT_FOUND | No ACTIVE membership in {orgId} | Treat as no access |
| 409 | INVALID_STATE | {orgId} is not the PLATFORM org | Call with the PLATFORM org id |
| 409 | CONFLICT | BR-2, details.reason: ALREADY_IN_BUSINESS (the owner belongs to a live Business), INVITATION_PENDING (the owner already has a pending Business-owner invitation), CROWN_STAFF (active Crown membership), MOVE_IN_PROGRESS (the owner's plants are being moved — retry in a minute). Nothing created | Show error.message; pick another owner or resolve the conflict |
| 422 | VALIDATION_FAILED | details.reason: "USER_NOT_REGISTERED" — no account uses owner.email (BR-2); nothing created | Ask the owner to sign up in the app first |
| 409 | ALREADY_EXISTS | owner.email already has a PENDING invitation in the new org. Practically impossible for a brand-new org, but the guard exists | Retry with a new Idempotency-Key |
| 422 | VALIDATION_FAILED | Body shape, unknown field, bad country/timezone/locale/currency/email | Show field errors |
| 428 | PRECONDITION_REQUIRED | Idempotency-Key missing | Generate a key, retry |
| 500 / 503 | INTERNAL / DEPENDENCY_UNAVAILABLE | Server or dependency error | Retry with the same Idempotency-Key |
Edge cases
- Idempotent replay: the same
Idempotency-Keyand body returns the stored201withIdempotent-Replayed: true; no second org is created. If the earlier call committed but its response was never stored (crash or timeout), the retry returns503 DEPENDENCY_UNAVAILABLErather than rebuilding the response; the Business does exist, so check the Business list before using a new key. - Atomic: the org and the owner invitation commit together, so a Business never exists without its owner's invitation.
- No email: the owner sees the invitation in-app. It can be resent (new token) with
:resendon the new org. acceptUrlis returned only outside prod, only on this response, and only whenINVITE_LINK_BASEis set.- The owner is not a member yet: they join the new org on the
BUSINESSrole only when they accept throughPOST /v1/invitations:accept.
Business permission limits
Purpose: an Admin decides what each Business can do (R-3a, owner decision 2026-11-03). Built
2026-11-03; not yet run against a deployed stage. All three routes are in the PLATFORM org, so a Business can
never read or change its own limit: without a PLATFORM membership the route is 404 NOT_FOUND, and any other org
in {orgId} is 409 INVALID_STATE.
Shape: a partial map of the 15 categories to a level, the same shape as a share's permsLimit. A missing key
means no limit for that category; {} is the same as no limit (null).
type BusinessLimit = {
businessOrgId: string;
permsLimit: Partial<Record<Category, Level>> | null; // null = no limit
version: number; // 0 = never set; If-Match for PUT
updatedAt?: string;
updatedBy?: { sub: string; displayName: string };
};
Effect: per category, the effective level is the lower of the role level and the limit, for:
- every membership in the Business org (the Business owner, Installers, any custom role), in every HTTP decision,
GET /v1/me/context, realtime tickets and alert audiences. A Super Admin member is never limited; - every share and customer portal the Business granted, including ones made before the limit (the limit is combined
with the grant's own
permsLimit/portalPermsLimit); - every new grant from the Business: shares, portals, invitations and role edits are checked against the limited levels, so a Business cannot pass on what it no longer holds.
Changes apply on the next request (the limit is read consistently with the membership). Live realtime sessions of
the Business's members get an access.revoked.v1 when a limit is lowered; End Users reached through its shares and
portals pick it up on their next ticket (at most 600 s).
GET /v1/orgs/{orgId}/businesses
- Authorization:
customers≥ VIEW in the PLATFORM org. - Query:
status(ACTIVE|SUSPENDED|CLOSED),q(2 to 64 characters; every word must start a word of the name or the code),limit(1–50; default 15 on the first page, 10 with acursor(lazy loading)),cursor(opaque). Unknown parameter, or aqwith no word of at least 2 characters:400 VALIDATION_FAILED.statusandqwere added by issue #14 (2026-11-13, not deployed). - Response
200:{ items: BusinessSummary[], nextCursor?: string }, sorted by name. Every non-personal OPERATOR org. - Paging: the cursor is tied to
statusandq. Reusing it with other filters →400 INVALID_CURSOR. Before issue #14, personal orgs could make a page short or empty while it still had anextCursor. A page now reads up to 5 times to fill itself, so this is rare. A page can still come back short; keep paging untilnextCursoris absent. - Counts (issue #14):
plantCount,customerCountandmemberCountcome from the Business's facet counters (approximate: true). They go stale while the stream-router is not deployed (KI-43), and a missing counter reads0. Do not present them as exact.installerCount(2026-11-19) is the exception: it is counted on read (aSelect: COUNTQuery over the Business's ACTIVE members on an Installer-type role), so it is exact. TheroleIdfacet counter is not used for it because it also counts REMOVED members.
type BusinessSummary = {
businessOrgId: string; code: string; name: string;
status: "ACTIVE" | "SUSPENDED" | "CLOSED";
owner: { sub: string; displayName: string } | null; // first ACTIVE Business-role member; null while the invitation is pending
creatorSub: string | null; // ADR 0026: the creator, a record only — since 2026-11-19 only Crown staff close a Business
permsLimit: PermsLimit | null;
version: number; // the Business LIMIT's version — If-Match of PUT …/limit
orgVersion: number; // ADR 0026: the Business org's version — If-Match of :suspend / :restore / :close / :reopen
plantCount: number; // issue #14: plants counter (COUNT#plants#ALL#ALL)
customerCount: number; // issue #14: ACTIVE customers
memberCount: number; // issue #14: ACTIVE members (End Users included)
installerCount: number; // 2026-11-19: ACTIVE members on an Installer-type role (any non-built-in role) — EXACT
approximate: true; // plantCount, customerCount and memberCount are approximate
};
GET /v1/orgs/{orgId}/businesses/{businessOrgId}/limit
- Authorization:
customers≥ VIEW in the PLATFORM org. - Response
200:BusinessLimit, withETag: "<version>"("0"when never set). - Errors:
404 NOT_FOUNDunknown Business;409 INVALID_STATEwhen{orgId}is not the PLATFORM org or{businessOrgId}is not a non-personal OPERATOR org.
PUT /v1/orgs/{orgId}/businesses/{businessOrgId}/limit
- Authorization:
customers≥ MANAGE in the PLATFORM org. - Headers:
If-Match: "<version>"required ("0"for the first write). Missing:428. NoIdempotency-Key(the write is versioned). - Body (strict):
{ "permsLimit": { … } | null }. - Escalation rule (not for a Super Admin, R-0): each limit value may be at most the caller's own level in that
category, and a category may only be raised (a higher value, or its key removed so it goes back to the Business
role's level) up to the caller's own level. Lowering is always allowed. Otherwise
403 FORBIDDEN,details: { reason: "ESCALATION", category }. - Side effects (one transaction): the limit item;
BUSINESS_LIMIT_CHANGEDwith per-categoryfrom/to(null= no limit) in the access logs of both the PLATFORM org and the Business org; and, when any category is lowered, oneaccess.revoked.v1(scope: "ORG",orgId= the Business,reason: "BUSINESS_NARROWED"). Sending the current limit again writes nothing and keeps the version. - Response
200: the newBusinessLimit,ETag= its version.
| Status | code | When |
|---|---|---|
| 403 | FORBIDDEN | customers below MANAGE, or details.reason: "ESCALATION" |
| 404 | NOT_FOUND | No PLATFORM membership, or unknown Business |
| 409 | INVALID_STATE | {orgId} not the PLATFORM org, or the target is not a Business |
| 409 | VERSION_CONFLICT | Stale If-Match; details.currentVersion |
| 422 | VALIDATION_FAILED | Unknown category or level, unknown body field |
| 428 | PRECONDITION_REQUIRED | If-Match missing |
Illustrative request (derived from the schema, not a captured execution)
PUT /v1/orgs/<platformOrgId>/businesses/<businessOrgId>/limit
If-Match: "0"
Content-Type: application/json
{ "permsLimit": { "firmware": "NONE", "commands": "VIEW" } }
{
"businessOrgId": "<businessOrgId>",
"permsLimit": { "firmware": "NONE", "commands": "VIEW" },
"version": 1,
"updatedAt": "2026-11-03T10:00:00.000Z",
"updatedBy": { "sub": "<adminSub>", "displayName": "<adminSub>" }
}
The Business owner's GET /v1/me/context then shows firmware: "NONE" and commands: "VIEW" for that org, and no
Installer there can exceed them.
Accept rules (Audit wave 1 (2026-10-27))
- Accepting requires a verified email; otherwise
403 FORBIDDEN. - Only the current token works: after a resend, the old token returns
404. - The user pool keeps the original email until a change is verified (
keepOriginal).
See also
- Team & Access API — the shared authorization model, scope shape and versioned-write conventions this API reuses
- Known issues & gaps — KI-28 (in-app only, no invitation email;
acceptUrlneedsshareLinkBaseUrlset)