Access requests API (B15)
Feature 003 (Organisations, Team & Access), user story 9 — the other direction from Shares. A share is the operator proactively granting access; an access request is a grantee org (one that already has some path to a plant — an existing share, or being the plant's recorded installer) asking the operator for a level, which the operator can approve (optionally at a lower level than asked) or reject. Approving always creates a brand-new, single-plant share — it never widens an existing broader share the requester might already hold.
:::caution Code-complete, not yet captured against a real deployment
As of 2026-10-03, packages/core/src/repositories/access-requests.ts,
packages/api/src/handlers/access-requests.ts and the three CDK routes
(lib/routes.ts's CreateAccessRequest, ListAccessRequests,
AccessRequestAction) are landed and unit-tested
(packages/api/test/handlers/access-requests.test.ts,
packages/api/test/authz/access-request-routes.test.ts,
packages/api/test/contract/openapi.test.ts). Every request/response shape
below is illustrative — derived from the OpenAPI schema
(docs/openapi.yaml) and the Zod schemas in packages/core/src/schemas.ts
(CreateAccessRequestInput, ApproveAccessRequestInput,
RejectAccessRequestInput, AccessRequest, AccessRequestView,
AccessRequestListItem, ApproveAccessRequestResult,
AccessRequestsQuery) — not a captured execution against a running stack.
The companion integration test
(packages/core/test/integration/access-requests.int.test.ts) is authored
but, like every *.int.test.ts on this repo, is never run by an agent —
only by a human against DynamoDB Local.
:::
Overview
| Op | Method + path | Auth | Idempotency |
|---|---|---|---|
| Create | POST /v1/plants/{plantId}/access-requests | plants ≥ VIEW in the active org (X-Org-Id) | Required |
| List | GET /v1/orgs/{orgId}/access-requests | sharing ≥ MANAGE (incoming) or plants ≥ VIEW (outgoing) | — |
| Approve | POST /v1/orgs/{orgId}/access-requests/{requestId}:approve | sharing ≥ MANAGE | — (versioned) |
| Reject | POST /v1/orgs/{orgId}/access-requests/{requestId}:reject | sharing ≥ MANAGE | — (versioned) |
Approve/reject are one wire route carrying two colon-verbs — see
Overview → Action routes. Create
needs an Idempotency-Key (CR-7), same convention as
Shares' create. Approve/reject are
versioned (If-Match/ETag).
Note the unusual org-context shape: create has no {orgId} path
segment at all — the requesting org comes from X-Org-Id (or the caller's
default org), same mechanism as
Realtime tickets. List and
approve/reject, by contrast, are {orgId}-scoped to the approver
(operator) org, same as every Shares route.
POST /v1/plants/{plantId}/access-requests
Purpose: "Request access" — a grantee org asks the plant's operator for a higher (or first) level.
- Auth: caller's
plants≥ VIEW in the active org (resolved fromX-Org-Idor the caller's stored default — missing both is400 ORG_CONTEXT_REQUIRED, same as Realtime tickets). That is only the floor — the active org must ALSO have a real path to this specific plant (an existing share whose selector covers it, or being the plant's recordedinstallerOrgId); neither →404 NOT_FOUND(the plant is invisible to this org, same "no path = doesn't exist" convention as every other 003 resource-visibility check — never a403). approverOrgIdis derived server-side from the plant's operator — never a body field.- By design: a request path exists only when your org holds a share
covering the plant, or is the plant's recorded installer (FR-051) — a
CUSTOMER org that sees the plant only through a CUSTOMER_PORTAL
relationship, with no share or installer role of its own, has no path
to request MORE access this way, and gets
404here.
Request
Headers
| Header | Required | Notes |
|---|---|---|
X-Org-Id | Conditionally | The requesting org, if it isn't the caller's stored default |
Idempotency-Key | Yes | [A-Za-z0-9_-]{1,128}. Missing → 428 PRECONDITION_REQUIRED, details.header: "Idempotency-Key". |
Content-Type | Yes | application/json |
Body (CreateAccessRequestInput, .strict())
| Field | Type | Required | Notes |
|---|---|---|---|
requestedLevel | VIEW|MONITOR|EDIT|SERVICE|FULL | Yes | Must exceed the requester's own current highest ACTIVE share level on this plant, if any — else 422. |
message | string, ≤ 500 chars | No | Shown to the approver alongside the request. |
Response — 201
{
requestId: string; // ULID
status: "PENDING";
expiresAt: string; // ISO-8601 — creation + 30 days
}
Status codes
| Status | code | When | FE action |
|---|---|---|---|
| 201 | — | Created | Show "Request sent"; the badge count on the approver side is eventually consistent, not pushed |
| 400 | ORG_CONTEXT_REQUIRED | No X-Org-Id and no stored default org | Prompt for an org context, same as Realtime tickets |
| 401 | UNAUTHENTICATED | No/bad token | Re-authenticate |
| 403 | FORBIDDEN | plants < VIEW in the active org | Hide the "Request access" action |
| 404 | NOT_FOUND | The active org has no share or installer relationship on this plant | Don't offer "Request access" for a plant with no existing relationship at all |
| 409 | ALREADY_EXISTS | A PENDING request already exists for this exact plant + requesting org | Surface the existing pending request instead of retrying |
| 422 | VALIDATION_FAILED | requestedLevel does not exceed the requester's current effective level on this plant | Disable levels at or below what the org already has |
| 428 | PRECONDITION_REQUIRED | Missing Idempotency-Key | Generate a key, retry |
| 500/503 | INTERNAL / DEPENDENCY_UNAVAILABLE | — | Retry with backoff |
Idempotent replay: same Idempotency-Key + same body replays the
original 201, same mechanism as Shares'
create.
GET /v1/orgs/{orgId}/access-requests
Purpose: the work-queue list — "incoming" requests an operator needs to decide on, or "outgoing" requests a grantee org itself has made.
- The one rule easy to get backwards:
direction=incoming(default) — requests made of{orgId}— needssharing≥ MANAGE in{orgId}(ADR 0014; wascustomers, from whichsharingderives for roles stored earlier — see Roles & permissions).direction=outgoing— requests made by{orgId}— needs onlyplants≥ VIEW. The two directions are never gated by the same category; a plain member withplants: VIEWbut nocustomersaccess at all can still see their own org's outgoing requests. - Oldest first — unlike the access-change log, which is newest first. This matches a work-queue's natural order (handle the oldest pending item first).
Query parameters
| Param | Type | Notes |
|---|---|---|
direction | incoming|outgoing | Default incoming |
status | PENDING|APPROVED|REJECTED|CANCELLED|EXPIRED | Optional. EXPIRED is derived at read time (a PENDING row past its 30-day expiresAt), never stored as such. |
limit | integer | ≤ 50; default 15 on the first page, 10 with a cursor (lazy loading) |
cursor | opaque string | From a previous page's nextCursor |
Response (illustrative)
{
items: Array<{
requestId: string;
plant: { plantId: string; name: string };
requesterOrg: { orgId: string; name: string };
requestedBy: { name: string };
requestedLevel: "VIEW"|"MONITOR"|"EDIT"|"SERVICE"|"FULL";
currentLevel?: "VIEW"|"MONITOR"|"EDIT"|"SERVICE"|"FULL"; // the requester's existing active share level on this plant, if any
message?: string;
status: "PENDING"|"APPROVED"|"REJECTED"|"CANCELLED"|"EXPIRED";
expired: boolean;
createdAt: string;
decidedAt?: string;
version: number; // N-45: always present; the If-Match value for :approve / :reject
}>;
nextCursor?: string;
}
This is a display-shaped row (AccessRequestListItem), not the raw
stored entity — it nests the plant/requester-org/requester-name previews so
the FE needs no extra calls to render the queue.
Status codes
| Status | code | When | FE action |
|---|---|---|---|
| 200 | — | OK | Render the queue; badge counts (GET /v1/me/context's badges.pendingAccessRequests) are eventually consistent facet counters, same caveat as Team's summary tiles |
| 401 | UNAUTHENTICATED | — | Re-authenticate |
| 403 | FORBIDDEN | Wrong category for the requested direction (see above) | Hide the relevant tab |
| 500/503 | — | — | Retry with backoff |
POST /v1/orgs/{orgId}/access-requests/{requestId}:approve
Purpose: grant the request — creates a new, single-plant share at the granted level.
- Auth:
sharing≥ MANAGE in{orgId}(the approver/operator org). From 2026-11-03 the Installer template heldsharing: MANAGE, so Installers approved and rejected requests too; RBAC-S6 lowered new Installer roles tosharing: VIEWon 2026-11-23, and the owner restoredMANAGEfor every Installer role on 2026-11-26. The granted level is still capped at the approver's own levels.If-Matchrequired (versioned) — missing is428, stale is409 VERSION_CONFLICT. - Business rule: the granted level is capped at the requested
level (never raised) and at the approver's own role perms
(
assertCanGrantLevel, same "a share can never exceed the sharer's own levels" rule as Shares' create) — exceeding either is a business-rule422, not silently clamped. - If the requester already holds an ACTIVE
PLANTSshare that contains this plant at a lower level, approving still creates a new single-plant share at the granted level rather than widening the existing one — "never silently widens other plants" is the contract's own wording.
Request
Headers: If-Match required.
Body (ApproveAccessRequestInput, .strict()), both optional:
| Field | Type | Notes |
|---|---|---|
level | VIEW|MONITOR|EDIT|SERVICE|FULL | Defaults to the request's own requestedLevel when omitted. Must not exceed it. |
expiresAt | ISO-8601 datetime | Expiry for the new share created by this approval, not the request itself. |
Response — 200
The decided request (full entity, ApproveAccessRequestResult — note this
is a different, richer shape than the list row above) plus shareId:
{
requestId: string; plantId: string; approverOrgId: string; requesterOrgId: string;
requestedBy: string; // Cognito sub
requestedLevel: "VIEW"|"MONITOR"|"EDIT"|"SERVICE"|"FULL";
message?: string;
status: "APPROVED";
decidedBy: string; decidedAt: string;
grantedLevel: "VIEW"|"MONITOR"|"EDIT"|"SERVICE"|"FULL";
shareId: string; // ULID of the newly created share
expiresAt: string; // the REQUEST's own 30-day expiry, unrelated to the new share's expiresAt
version: number;
createdAt: string; updatedAt: string; createdBy: string; updatedBy: string;
}
Status codes
| Status | code | When | FE action |
|---|---|---|---|
| 200 | — | Approved — a new share now exists | Remove from the incoming queue; the requester's next request sees the new share via Shares or GET /v1/me/context |
| 401 | UNAUTHENTICATED | — | Re-authenticate |
| 403 | FORBIDDEN | customers < MANAGE, or details.reason: "ESCALATION" — the granted level exceeds the approver's own role perms | Hide the action, or (ESCALATION) offer a lower level |
| 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 |
| 404 | NOT_FOUND | Unknown requestId in this org | Refresh the queue |
| 409 | VERSION_CONFLICT | Stale If-Match | Re-fetch, retry |
| 409 | INVALID_STATE | The request is not PENDING (already decided, or past its 30-day expiresAt) | Refresh the queue — nothing to do |
| 422 | VALIDATION_FAILED | level in the body exceeds the request's own requestedLevel | Offer only levels ≤ requestedLevel |
| 428 | PRECONDITION_REQUIRED | Missing If-Match | Fetch the current ETag first |
| 500/503 | — | — | Retry with backoff |
POST /v1/orgs/{orgId}/access-requests/{requestId}:reject
Purpose: decline the request, with a reason.
Auth: same sharing ≥ MANAGE + If-Match as approve. No escalation
check — rejecting never grants anything.
Request
Body (RejectAccessRequestInput, .strict()):
| Field | Type | Required | Notes |
|---|---|---|---|
reason | string, 1–500 chars | Yes | Shown to the requester. |
Response — 200
The decided request as a plain AccessRequestView (same shape as
:approve's response minus shareId/grantedLevel, plus
decisionReason):
{
requestId: string; /* …same fields as :approve above… */
status: "REJECTED";
decidedBy: string; decidedAt: string;
decisionReason: string;
expiresAt: string; version: number; createdAt: string; updatedAt: string; createdBy: string; updatedBy: string;
}
Status codes
| Status | code | When | FE action |
|---|---|---|---|
| 200 | — | Rejected | Remove from the incoming queue |
| 401 | UNAUTHENTICATED | — | Re-authenticate |
| 403 | FORBIDDEN | customers < MANAGE | Hide the action |
| 404 | NOT_FOUND | Unknown requestId | Refresh the queue |
| 409 | VERSION_CONFLICT | Stale If-Match | Re-fetch, retry |
| 409 | INVALID_STATE | Not PENDING (already decided, or expired) | Refresh — nothing to do |
| 422 | VALIDATION_FAILED | reason missing or empty | Require the field client-side before submit |
| 428 | PRECONDITION_REQUIRED | Missing If-Match | Fetch the current ETag first |
| 500/503 | — | — | Retry with backoff |
Edge cases
- Expiry is evaluated at read AND decide time. A
PENDINGrequest past its 30-dayexpiresAtis shown asstatus: "EXPIRED"on the list (derived, never stored) and can no longer be approved or rejected — both actions return409 INVALID_STATEexactly as if it had already been decided. There is no route to extend or renew an expired request; the requester must submit a new one (subject to the same duplicate-pending guard, which no longer blocks once the old one has expired). - The pending-duplicate guard is per plant + requesting org, not per
level — a second request for a different level on the same plant,
while one is already
PENDING, is still409 ALREADY_EXISTS. - Approving never touches other plants. Even if the requester already holds a broad multi-plant share, approval always creates a fresh, single-plant share scoped to exactly the plant in the request.
- Idempotency-Key is required only on create, not on approve/reject
(those are versioned via
If-Matchinstead, same convention as every other 003 decision/mutation route that isn't a create).
Audit
Every transition writes exactly one access-change log entry in the SAME
atomic write as the state change — see the access-change
log:
ACCESS_REQUESTED on create, ACCESS_REQUEST_APPROVED on approve (the
share creation is summarised in the same entry, not a second one),
ACCESS_REQUEST_REJECTED on reject.