Skip to main content

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​

OpMethod + pathAuthIdempotency
CreatePOST /v1/plants/{plantId}/access-requestsplants ≥ VIEW in the active org (X-Org-Id)Required
ListGET /v1/orgs/{orgId}/access-requestssharing ≥ MANAGE (incoming) or plants ≥ VIEW (outgoing)—
ApprovePOST /v1/orgs/{orgId}/access-requests/{requestId}:approvesharing ≥ MANAGE— (versioned)
RejectPOST /v1/orgs/{orgId}/access-requests/{requestId}:rejectsharing ≥ 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 from X-Org-Id or the caller's stored default — missing both is 400 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 recorded installerOrgId); 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 a 403).
  • approverOrgId is 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 404 here.

Request​

Headers

HeaderRequiredNotes
X-Org-IdConditionallyThe requesting org, if it isn't the caller's stored default
Idempotency-KeyYes[A-Za-z0-9_-]{1,128}. Missing → 428 PRECONDITION_REQUIRED, details.header: "Idempotency-Key".
Content-TypeYesapplication/json

Body (CreateAccessRequestInput, .strict())

FieldTypeRequiredNotes
requestedLevelVIEW|MONITOR|EDIT|SERVICE|FULLYesMust exceed the requester's own current highest ACTIVE share level on this plant, if any — else 422.
messagestring, ≤ 500 charsNoShown to the approver alongside the request.

Response — 201​

{
requestId: string; // ULID
status: "PENDING";
expiresAt: string; // ISO-8601 — creation + 30 days
}

Status codes​

StatuscodeWhenFE action
201—CreatedShow "Request sent"; the badge count on the approver side is eventually consistent, not pushed
400ORG_CONTEXT_REQUIREDNo X-Org-Id and no stored default orgPrompt for an org context, same as Realtime tickets
401UNAUTHENTICATEDNo/bad tokenRe-authenticate
403FORBIDDENplants < VIEW in the active orgHide the "Request access" action
404NOT_FOUNDThe active org has no share or installer relationship on this plantDon't offer "Request access" for a plant with no existing relationship at all
409ALREADY_EXISTSA PENDING request already exists for this exact plant + requesting orgSurface the existing pending request instead of retrying
422VALIDATION_FAILEDrequestedLevel does not exceed the requester's current effective level on this plantDisable levels at or below what the org already has
428PRECONDITION_REQUIREDMissing Idempotency-KeyGenerate a key, retry
500/503INTERNAL / 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} — needs sharing ≥ MANAGE in {orgId} (ADR 0014; was customers, from which sharing derives for roles stored earlier — see Roles & permissions). direction=outgoing — requests made by {orgId} — needs only plants ≥ VIEW. The two directions are never gated by the same category; a plain member with plants: VIEW but no customers access 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​

ParamTypeNotes
directionincoming|outgoingDefault incoming
statusPENDING|APPROVED|REJECTED|CANCELLED|EXPIREDOptional. EXPIRED is derived at read time (a PENDING row past its 30-day expiresAt), never stored as such.
limitinteger≤ 50; default 15 on the first page, 10 with a cursor (lazy loading)
cursoropaque stringFrom 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​

StatuscodeWhenFE action
200—OKRender the queue; badge counts (GET /v1/me/context's badges.pendingAccessRequests) are eventually consistent facet counters, same caveat as Team's summary tiles
401UNAUTHENTICATED—Re-authenticate
403FORBIDDENWrong 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 held sharing: MANAGE, so Installers approved and rejected requests too; RBAC-S6 lowered new Installer roles to sharing: VIEW on 2026-11-23, and the owner restored MANAGE for every Installer role on 2026-11-26. The granted level is still capped at the approver's own levels. If-Match required (versioned) — missing is 428, stale is 409 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-rule 422, not silently clamped.
  • If the requester already holds an ACTIVE PLANTS share 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:

FieldTypeNotes
levelVIEW|MONITOR|EDIT|SERVICE|FULLDefaults to the request's own requestedLevel when omitted. Must not exceed it.
expiresAtISO-8601 datetimeExpiry 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​

StatuscodeWhenFE action
200—Approved — a new share now existsRemove from the incoming queue; the requester's next request sees the new share via Shares or GET /v1/me/context
401UNAUTHENTICATED—Re-authenticate
403FORBIDDENcustomers < MANAGE, or details.reason: "ESCALATION" — the granted level exceeds the approver's own role permsHide the action, or (ESCALATION) offer a lower level
403FORBIDDENdetails.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
404NOT_FOUNDUnknown requestId in this orgRefresh the queue
409VERSION_CONFLICTStale If-MatchRe-fetch, retry
409INVALID_STATEThe request is not PENDING (already decided, or past its 30-day expiresAt)Refresh the queue — nothing to do
422VALIDATION_FAILEDlevel in the body exceeds the request's own requestedLevelOffer only levels ≤ requestedLevel
428PRECONDITION_REQUIREDMissing If-MatchFetch 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()):

FieldTypeRequiredNotes
reasonstring, 1–500 charsYesShown 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​

StatuscodeWhenFE action
200—RejectedRemove from the incoming queue
401UNAUTHENTICATED—Re-authenticate
403FORBIDDENcustomers < MANAGEHide the action
404NOT_FOUNDUnknown requestIdRefresh the queue
409VERSION_CONFLICTStale If-MatchRe-fetch, retry
409INVALID_STATENot PENDING (already decided, or expired)Refresh — nothing to do
422VALIDATION_FAILEDreason missing or emptyRequire the field client-side before submit
428PRECONDITION_REQUIREDMissing If-MatchFetch the current ETag first
500/503——Retry with backoff

Edge cases​

  • Expiry is evaluated at read AND decide time. A PENDING request past its 30-day expiresAt is shown as status: "EXPIRED" on the list (derived, never stored) and can no longer be approved or rejected — both actions return 409 INVALID_STATE exactly 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 still 409 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-Match instead, 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.