Skip to main content

Partner businesses API (C19)

Feature 004, user story 4. A partner is a PARTNER org (dealer, installer, distributor or O&M partner) linked to your operator org by a partner profile (ORG#<op>/REL#PARTNER#<partner>). Installer partners populate the installer dropdown on the create-plant form.

:::caution Deployed; no captured run yet Deployed on dev (verified live 2026-10-13). Lists filtered by relationship/status use GSI3, deployed 2026-10-13, so they are expected to work now, not yet re-verified on dev. The DynamoDB key fix for get and PATCH (previously 500) is deployed to dev 2026-10-13; not yet re-verified with a signed-in call. As of 2026-10-13 these routes are in lib/routes.ts (ListPartners, CreatePartner, GetPartner, UpdatePartner). Handler: packages/api/src/handlers/partners.ts. Core: packages/core/src/partners/repository.ts. They are unit-tested and match docs/openapi.yaml. The integration test partners-004.int.test.ts has been written but not run. JSON examples are illustrative, derived from PartnerProfile, CreatePartnerInput, UpdatePartnerInput, PartnerListQuery and PartnerListResponse. The issue #14 write rules below (INSTALLER only, Crown PLATFORM org only) were committed 2026-11-13 and are not deployed. :::

:::info Issue #14 (2026-11-13): partners are a Crown-only tab The installation companies are the Businesses, so partner orgs are now created and edited only from the Crown PLATFORM org. A Business can still change the status of a partner it created earlier. DEALER, DISTRIBUTOR and OM_PARTNER are retired for writes; they still appear on relationships stored earlier and in the list filter. :::

Common rules (auth, path-authoritative {orgId}, X-Org-Id mismatch → 400, ETag/If-Match, strict bodies, cursors) are the same as for Customers.

Routes​

MethodPathcustomers levelHeaders
GET/v1/orgs/{orgId}/partnersVIEW—
POST/v1/orgs/{orgId}/partnersMANAGEIdempotency-Key required
GET/v1/orgs/{orgId}/partners/{partnerOrgId}VIEW—
PATCH/v1/orgs/{orgId}/partners/{partnerOrgId}MANAGEIf-Match required

There is no DELETE. To end a partnership, set status: "SUSPENDED".

PartnerProfile​

FieldTypeNotes
partnerOrgId, operatorOrgIdULID
codestringPB-NN. Missing on relationships created before 004
namestring1–160
relationshipDEALER | INSTALLER | DISTRIBUTOR | OM_PARTNERReads only. Create and PATCH accept INSTALLER only
contact{name?, jobTitle?, phone?, email?}
city, partnerSince, contract (≤200), note (≤500)optional
statusONBOARDING (initial) | ACTIVE | SUSPENDED
accessCeiling, plantCount, staffCountread-only, from 003 when available. Edit the ceiling through Shares (B13)
version, createdAt, updatedAt

List​

Query parameters: relationship, status, q (2–64 characters), limit (1–50; default 15 on the first page, 10 with a cursor (lazy loading)), cursor. Response: {items, nextCursor?, relationshipCounts}. relationshipCounts maps each relationship to an approximate count; use it for the filter-chip badges.

{ "items": [{ "partnerOrgId": "01JC…", "operatorOrgId": "01JA…", "code": "PB-07", "name": "SunFix Installers",
"relationship": "INSTALLER", "status": "ACTIVE", "version": 3 }],
"relationshipCounts": { "INSTALLER": 4, "DEALER": 2 } }

:::note Admin-web 2026-11-24 Page 1 of the list also carries total, the number of partners across every status. It is approximate. See Admin-web list totals, counts and filter options. :::

Create​

Body: name, relationship (required, INSTALLER only); contact?, city?, partnerSince?, contract?, note?, invite?: {email}.

Only the Crown PLATFORM org can create a partner. From any other {orgId} (a Business) the response is 409 INVALID_STATE and nothing is written; Businesses are created with POST …/businesses. Any other relationship → 422 VALIDATION_FAILED.

Every create makes a new partner org; you cannot link an existing org through this route. Returns 201 with the flat profile (status: "ONBOARDING", plus invitation if invite was sent), Location and ETag. Emits org.upserted.v1. Idempotency behaves exactly as for customer create.

Edit​

PATCH with If-Match. Fields: name, relationship (INSTALLER only), contact, city, contract, note, status. null clears contact, city, contract or note.

Outside the Crown PLATFORM org, only a body with status alone is accepted (to suspend or reactivate a partner). Any other field there → 409 INVALID_STATE.

Setting status to SUSPENDED writes access-log PARTNER_SUSPENDED and emits access.revoked.v1 (reason PARTNER_SUSPENDED). From the partner's next request on, the access loader (access/loader.ts) checks the partner relationship's status, and shares from a SUSPENDED partner grant nothing. No token refresh is needed. The shares are not deleted, so setting status back to ACTIVE restores access. Ask for confirmation in the UI first.

Errors and what the FE should do​

StatusCodeFE action
400VALIDATION_FAILED / INVALID_CURSOR / MALFORMED_REQUESTFix the request; for a cursor error, reload page 1
403FORBIDDENHide write actions below MANAGE
404NOT_FOUNDNot a partner of this org: remove the row
409INVALID_STATECreate, or a PATCH field other than status, from an org that is not the Crown PLATFORM org. Hide those actions outside Crown
409VERSION_CONFLICTRefetch and let the user reapply
409ALREADY_EXISTSThe relationship item already exists (rare; a generated-id collision). Refetch the list
409CONFLICT / IDEMPOTENCY_IN_PROGRESSRetry with the same key
415UNSUPPORTED_MEDIA_TYPEBug
422VALIDATION_FAILED / IDEMPOTENCY_KEY_REUSEDShow the field errors (including a relationship other than INSTALLER) / use a new key
428PRECONDITION_REQUIREDBug: send Idempotency-Key / If-Match
503DEPENDENCY_UNAVAILABLEBack off and retry