Create a plant: FE integration guide
Everything the mobile app needs to build the create-plant
wizard (screens 08 → 10; the battery screen 11 was removed on 2026-11-20) and handle its result (screen 12) against
POST /v1/plants: every field, every option, every validation rule, the
exact server error text, the conditional UI each rule implies, and what to
do on success and on each kind of failure.
:::info How this page was verified
Every rule here was read from packages/core/src/schemas.ts and
packages/core/src/repositories/plants.ts at commit b0681da (deployed to
dev on 2026-09-24). Every error message quoted on this page was
produced on 2026-09-25 by running that deployed CreatePlantInput schema
locally (Zod 3.25.76) against each payload shown. They were not captured
from the dev API. Request/response JSON blocks are illustrative,
derived from the code, unless a block says otherwise.
The screen designs aren't in either repo. The "Suggested message" and "Info box" texts below are suggested wording that says what the rule means. If the design has its own copy, the design wins. The rule behind it doesn't change. :::
:::warning Changed 2026-11-20: plant create takes no battery data; the creator owns the plant Owner decision 2026-11-20 ("plant creation and device management flows", ADR 0029). They replace the 2026-11-19 battery step.
- No battery step. Create a simple plant, then register the inverter over the TCP WebSocket (
register), then optionally add batteries to that device (add_device_battery). See After the plant is created. - Older builds keep working.
batteriesand the flathasBattery/batteryCapacityKwh/batteryPowerKw/batteryBrand/batteryBrandOtherare accepted with any value and ignored — never a422, never stored, never sent to TCP. Remove them from the request builder. - Owner. The user who creates the plant is stored as its owner (
ownerUserSub, sent to TCP onplant.upserted.v1); TCP makes the plant's devices and batteries follow that owner. No request or response field changes for the app. - The response's
hasBatterystays derived:trueonly once a device bound to the plant has a battery on TCP (falseon a new plant).
Verified against packages/core/src/schemas.ts (CreatePlantInput, RetiredBatteryInput) and
packages/core/src/plants/repository.ts on 2026-11-20 by unit tests; not yet exercised against the deployed dev
API.
:::
Read this first: the mistakes that return 422
From 2026-09-24 12:46 to 2026-09-25 05:17 UTC, every create from the app
returned 422 VALIDATION_FAILED ("Request validation failed"). The
contract had changed (commit b0681da) and the app's request body hadn't.
Check your request builder against this list before anything else.
| # | Mistake | What the server says | Fix |
|---|---|---|---|
| 1 | A number typed into a text field is sent as a string ("15") | Expected number, received string | double.tryParse(text.trim()), send the double, or leave the key out when it's null |
| 2 | pvCapacityKwp: 0 sent as "no value" | Number must be greater than 0 | Leave the key out (or send null). 0 is a value, and it's invalid |
| 3 | (retired 2026-11-20) battery fields | none — batteries and the flat battery fields are now accepted with any value and ignored | Stop sending them; add batteries on TCP after registering the inverter |
| 4 | An enum sent in the wrong case: Dart's MyEnum.residential.name is "residential" | Invalid enum value. Expected 'RESIDENTIAL' | … received 'residential' | Map each Dart enum to the exact upper-case API string. Enums are case-sensitive |
| 5 | An old-contract or misspelled key (capacityKw, batteryKwh, a string address) | Unrecognized key(s) in object: '…' / Expected object, received string | Build the body from the field list below only. The body is strict: unknown keys are rejected, not ignored |
:::tip The 422 already tells you the field
The response body names every failing field in error.details.fieldErrors.
Log it in debug builds, and show it to the user in the matching wizard step
(see Handling a 422). The server also logs a WARN
validation_failed line with the failing field paths and codes (no values,
no body), so the backend team can find it from CloudWatch too — this was a
known gap (fixed) during the 2026-09-24/25 incident described above.
:::
The flow at a glance
Screen 08 Plant Details ─┐
Screen 09 Solar System │ collected locally, no network calls
Screen 10 Grid Connection ─┘ (no battery step since 2026-11-20)
│ "Create plant"
▼
POST /v1/plants (one request, the whole wizard)
│
┌──────┴────────────┬────────────────────┬──────────────────────┐
201 422 401 network error / 5xx
Screen 12 show errors on refresh token, outcome unknown: check
Plant Created the right step retry once GET /v1/plants before retrying
- There is no per-step endpoint and no draft. Validate each step on the device as the user goes. The server sees the wizard only once, at submit.
- Endpoint:
POST /v1/plants. Base URL: see API overview → Base URL. - Headers:
Authorization: Bearer <Cognito ID token>andContent-Type: application/json. Both are required. - Who can call it: any signed-in user. The caller becomes the plant's
OWNER(and, since 2026-11-20, its stored ownerownerUserSub). - What the server does: it validates the body, then writes the plant
and the caller's
OWNERmembership in one atomic DynamoDB transaction. Either both exist afterwards or neither does. There is never a plant nobody can see.
Request body: quick reference
{
// Step 1 · Screen 08 · Plant Details
name: string; // required
plantType: 'RESIDENTIAL' | 'COMMERCIAL' | 'INDUSTRIAL'; // required
countryCode: string; // required, e.g. "PK"
address?: { // optional
formatted?: string;
city?: string;
region?: string;
latitude?: number; // with longitude, or neither
longitude?: number;
} | null;
timezone?: string | null; // required unless countryCode is "PK"
// Step 2 · Screen 09 · Solar System
solarMode: 'NONE' | 'SELF_CONSUMPTION' | 'GRID_EXPORT' | 'SELF_CONSUMPTION_GRID_EXPORT'; // required
pvCapacityKwp?: number | null; // required unless solarMode is NONE, forbidden when NONE
// Step 3 · Screen 10 · Grid Connection
gridConnection: 'GRID_CONNECTED' | 'OFF_GRID'; // required
electricityRate?: { amountPerKwh: number; currency: string } | null; // optional
// Retired 2026-11-20 — accepted with any value and IGNORED, do not send:
// batteries, hasBattery, batteryCapacityKwh, batteryPowerKw, batteryBrand, batteryBrandOther
}
Rules that apply to every field:
- Numbers are JSON numbers.
15and15.5are fine."15"is a422. Decimals are accepted and stored as sent (no rounding). - Enums are exact, upper-case strings.
"residential"is a422. - "Not answered" on an optional field can be sent three ways, and all
three mean the same thing: leave the key out, send
null, or send a blank or whitespace-only string"". Nothing is stored. Dart's defaultnull-emitting serialisers are fine, so you don't needincludeIfNull: false. nullon a required field is a422(Expected string, received null).- Strings are trimmed before length checks, and stored trimmed.
- Unknown keys are rejected at the top level, inside
addressand insideelectricityRate. This includes server-owned fields: don't sendplantId,status,createdAtorrole.
Step 1 · Screen 08 · Plant Details
name (Plant Name)
| Type | string |
| Required | Yes |
| Validation | Trimmed, then 1-120 characters. Whitespace-only is empty |
| Uniqueness | None. Two plants may have the same name, including on the same account |
| Payload | Server error on name | Suggested message |
|---|---|---|
| key missing | Required | "Enter a name for your plant." |
"" or " " | String must contain at least 1 character(s) | "Enter a name for your plant." |
| 121+ characters | String must contain at most 120 character(s) | "Plant name can be at most 120 characters." |
null | Expected string, received null | (client bug: always send a string) |
Client-side: disable Next until name.trim() is not empty, and set
maxLength: 120 on the text field.
plantType (Plant Type)
| Value | Meaning |
|---|---|
RESIDENTIAL | A home |
COMMERCIAL | A shop, office or other business premises |
INDUSTRIAL | A factory, farm or other industrial site |
Required, exactly one, case-sensitive; any other value is 422 VALIDATION_FAILED (owner decision Q1, 2026-10-27 removed the earlier UTILITY/OTHER). Stored legacy values are read tolerantly: a plant still carrying a retired UTILITY or OTHER is returned as INDUSTRIAL or COMMERCIAL respectively (readPlantType in packages/core/src/schemas.ts), so no response carries a value outside the three. The owner rewrites stored values with npm run migrate:plant-types (see Operations).
| Payload | Server error on plantType |
|---|---|
| key missing | Required |
"residential", "FARM" | Invalid enum value. Expected 'RESIDENTIAL' | 'COMMERCIAL' | 'INDUSTRIAL', received '…' |
Client-side: a single-select with no default, and Next disabled until one is chosen. Suggested message: "Choose a plant type."
countryCode (Country / Region)
| Type | string, ISO 3166-1 alpha-2 (PK, AE, GB, …) |
| Required | Yes |
| Validation | Exactly 2 letters, then checked against the 249 assigned codes. Case-insensitive; stored upper-case ("pk" → "PK") |
| Rejected on purpose | UK (use GB), ZZ, XK (Kosovo; user-assigned, not an official code) |
| Side effect | Decides whether timezone is required (see timezone) |
| Payload | Server error(s) |
|---|---|
| key missing | countryCode: Required |
"PAK", "P1" | countryCode: must be an ISO 3166-1 alpha-2 code |
"UK", "ZZ" | countryCode: is not an assigned ISO 3166-1 alpha-2 code, and timezone: is required when countryCode is not PK (if no timezone was sent) |
Client-side: use a country picker that returns alpha-2 codes. Never a
free-text field. Default it to PK if that's the design.
address (Plant Address)
Optional. The whole object and every part of it are optional: the screen leaves out any part the user doesn't give.
| Part | Type | Validation | Source on the screen |
|---|---|---|---|
formatted | string | Trimmed, ≤ 400 chars | Full address line |
city | string | Trimmed, ≤ 120 chars | |
region | string | Trimmed, ≤ 120 chars | Province / state |
latitude | number | -90 to 90 | "Use current location" / "Pick on map" |
longitude | number | -180 to 180 | "Use current location" / "Pick on map" |
latitudeandlongitudego together: send both or neither.- Blank parts (
""," ",null) are dropped. An address with no parts left ({}, or all blank) is not stored at all, and the response won't containaddress. - The address is an object. A plain string (
"address": "Lahore") is the old contract and returns a422. - The server doesn't geocode or cross-check anything. It doesn't check that
the coordinates are in
countryCode, or thatcitymatches them.
| Payload | Server error on address | Suggested message |
|---|---|---|
"Lahore" (string) | Expected object, received string | (client bug) |
{ "latitude": 24.8 } | latitude and longitude must be supplied together | "Location is incomplete. Pick the location again." |
{ "latitude": 91, "longitude": 67 } | Number must be less than or equal to 90 | "That location isn't valid. Pick it again." |
{ "latitude": "24.8", … } | Expected number, received string (once per bad part) | (client bug: send numbers) |
{ "city": "<121 chars>" } | String must contain at most 120 character(s) | "City name is too long." |
{ "street": "…" } | Unrecognized key(s) in object: 'street' | (client bug) |
:::caution Address errors don't say which part failed
The error response flattens one level, so every problem inside address
is reported under the single key fieldErrors.address, not
address.latitude. Validate each part on the device (lengths, the lat/long
pair) so the user never depends on this message.
:::
timezone (no screen)
The app has no time-zone screen, but the plant needs one.
countryCode | timezone sent? | Result |
|---|---|---|
PK | no / null / "" | ✅ Stored as Asia/Karachi |
PK | "Asia/Karachi" (or any valid zone) | ✅ Stored as sent |
| anything else | no / null / "" | ❌ timezone: is required when countryCode is not PK |
| anything else | a valid IANA zone, e.g. "Asia/Dubai" | ✅ Stored |
- Validation: ≤ 64 characters, matched case-insensitively against
Intl.supportedValuesOf('timeZone')plus the literalUTC(KI-19 fixed). Stored in canonical case ("asia/karachi"→"Asia/Karachi"). Rejected with422(is not an IANA time zone): an unknown zone ("Mars/Base"), a UTC offset ("+05:00"), or an abbreviation ("PKT","GMT+5") — none of those carry daylight-saving rules the way a real IANA zone does. - The server doesn't check that the zone matches the country.
countryCode: "AE"withtimezone: "Asia/Karachi"is accepted. - Send an IANA name (
Area/City), orUTC. Nothing else validates. - For a non-PK plant, fill
timezonein without asking the user. Either read the device's IANA zone (for example with theflutter_timezonepackage) when the plant is where the phone is, or map the chosen country to its zone. Ask the user only for countries with several zones.
Step 2 · Screen 09 · Solar System
solarMode (the four cards)
| Value (screen order) | Meaning | Allowed with OFF_GRID? | pvCapacityKwp |
|---|---|---|---|
NONE | No solar panels installed | ✅ | Must be omitted |
SELF_CONSUMPTION | Solar powers the site, nothing is sold to the utility | ✅ | Required |
GRID_EXPORT | Solar is exported (sold) to the utility | ❌ | Required |
SELF_CONSUMPTION_GRID_EXPORT | Solar powers the site and the surplus is exported | ❌ | Required |
Required, exactly one, case-sensitive.
| Payload | Server error on solarMode |
|---|---|
| key missing | Required |
"HYBRID", "self_consumption" | Invalid enum value. Expected 'NONE' | 'SELF_CONSUMPTION' | 'GRID_EXPORT' | 'SELF_CONSUMPTION_GRID_EXPORT', received '…' |
an exporting mode with gridConnection: "OFF_GRID" | an OFF_GRID plant cannot use an exporting solar mode (see Step 3) |
pvCapacityKwp (Installed PV Capacity)
| Type | JSON number, kWp (kilowatt-peak) |
| Meaning | The panels' total DC rating, not the inverter's rating |
| Required | Yes when solarMode isn't NONE. Must be left out (or null/"") when solarMode is NONE |
| Validation | > 0 and ≤ 100,000. Decimals allowed (5.25) |
| Payload | Server error on pvCapacityKwp | Suggested message |
|---|---|---|
missing / null / "" with solar installed | is required when solar is installed | "Enter your installed solar capacity." |
0, -1 | Number must be greater than 0 | "Capacity must be more than 0 kWp." |
100001 | Number must be less than or equal to 100000 | "Capacity can be at most 100,000 kWp." |
"5" (string) | Expected number, received string | (client bug: parse the text) |
any value with solarMode: "NONE" | must be omitted when solarMode is NONE | (client bug: clear it) |
Conditional UI:
- Show the capacity field only after a card other than
NONEis picked, and make it required then. - When the user switches to
NONE, clear any capacity already typed. A stale value left in state is a422. - Use a numeric keyboard (
TextInputType.numberWithOptions(decimal: true)) and parse withdouble.tryParse. If the locale may type1,000or5,5, normalise the separators first:double.tryParse("1,000")isnull.
Step 3 · Screen 10 · Grid Connection
gridConnection
| Value | Meaning |
|---|---|
GRID_CONNECTED | The site is connected to the utility grid |
OFF_GRID | The site has no utility connection |
Required, exactly one, case-sensitive. Missing → Required. Anything else →
Invalid enum value. Expected 'GRID_CONNECTED' | 'OFF_GRID', received '…'.
The off-grid rule (info box)
An OFF_GRID plant can't export, so it can't use GRID_EXPORT or
SELF_CONSUMPTION_GRID_EXPORT. This is the rule behind screen 10's info box.
The solar mode is picked on screen 09, before the grid question on screen 10. So the conflict shows up on screen 10:
| Screen 09 choice | User picks OFF_GRID on screen 10 | What the app should do |
|---|---|---|
NONE or SELF_CONSUMPTION | fine | Nothing |
GRID_EXPORT or SELF_CONSUMPTION_GRID_EXPORT | conflict | Show the info box and block Next until the user either picks GRID_CONNECTED or goes back and picks a non-exporting solar mode |
Info box (suggested): "Off-grid systems can't send power to the utility. To continue, choose Grid connected, or go back and pick a solar option that doesn't export."
If the app sends the conflict anyway, the server returns
solarMode: an OFF_GRID plant cannot use an exporting solar mode. The
error is on solarMode, not gridConnection, so show it on screen 09.
electricityRate (Electricity Rate)
Optional. It's the price of one unit (1 kWh) from the utility.
| Part | Type | Required (if the object is sent) | Validation |
|---|---|---|---|
amountPerKwh | JSON number | Yes | ≥ 0 and ≤ 100,000. 0 is allowed |
currency | string | Yes | Exactly 3 letters (ISO 4217 shape, e.g. PKR). Case-insensitive; stored upper-case. Shape only: it isn't checked against the real currency list or against countryCode |
- To send no rate: leave the key out, or send
null. Don't send{}: an empty object is a422(Requiredonce for each missing part). - If the user typed an amount, send the object with both parts. Take
currencyfrom the country (e.g.PK→PKR) unless the design lets the user pick it. - It isn't restricted by
gridConnection: anOFF_GRIDplant may still send a rate.
| Payload | Server error on electricityRate | Suggested message |
|---|---|---|
{ "amountPerKwh": 65 } | Required | (client bug: add the currency) |
{} | Required, Required | (client bug: send null instead) |
{ "amountPerKwh": "65", … } | Expected number, received string | (client bug: parse the text) |
{ "amountPerKwh": -1, … } | Number must be greater than or equal to 0 | "Rate can't be negative." |
{ …, "currency": "Rs" } | must be an ISO 4217 code | (client bug: send PKR) |
{ …, "unit": "kWh" } | Unrecognized key(s) in object: 'unit' | (client bug) |
As with address, every error inside the object is reported under the one
key fieldErrors.electricityRate.
After the plant is created: inverter and batteries on TCP
Owner decision 2026-11-20. The create wizard has no battery step. Battery details live per device on the TCP server:
POST /v1/plants(this page) → keep theplantId.- Register the inverter into the plant over the TCP WebSocket (
registerwith theplantId) — see the TCP server's device registration guide. - Optionally add one or more batteries to that device (
add_device_battery) — see the TCP server's device batteries guide.
The plant's hasBattery on HTTP turns true once TCP reports that a device
bound to it has a battery.
Older app builds still send batteries or the flat hasBattery /
batteryCapacityKwh / batteryPowerKw / batteryBrand /
batteryBrandOther. The server accepts them with any value and drops them:
no 422, nothing stored, nothing sent to TCP.
Building the body in Dart (illustrative)
This isn't code from the app repo. It shows the rules above in one place: parse numbers, upper-case enum strings, and leave keys out when they don't apply.
// Map every Dart enum to the exact API string. Dart's `.name` is
// lower-camel-case ("residential"), which the server rejects.
const plantTypeApi = {
PlantType.residential: 'RESIDENTIAL',
PlantType.commercial: 'COMMERCIAL',
PlantType.industrial: 'INDUSTRIAL',
};
const solarModeApi = {
SolarMode.none: 'NONE',
SolarMode.selfConsumption: 'SELF_CONSUMPTION',
SolarMode.gridExport: 'GRID_EXPORT',
SolarMode.selfConsumptionGridExport: 'SELF_CONSUMPTION_GRID_EXPORT',
};
const gridConnectionApi = {
GridConnection.gridConnected: 'GRID_CONNECTED',
GridConnection.offGrid: 'OFF_GRID',
};
double? parseNumber(String text) =>
double.tryParse(text.trim().replaceAll(',', ''));
Map<String, dynamic> buildCreatePlantBody(PlantWizardState s) {
final pv = parseNumber(s.pvCapacityText);
final rate = parseNumber(s.electricityRateText);
return {
'name': s.name.trim(),
'plantType': plantTypeApi[s.plantType]!,
'countryCode': s.countryCode, // alpha-2 from the picker
if (s.timezone != null) 'timezone': s.timezone, // IANA name; required outside PK
if (s.address != null) 'address': {
if (s.address!.formatted.trim().isNotEmpty) 'formatted': s.address!.formatted.trim(),
if (s.address!.city.trim().isNotEmpty) 'city': s.address!.city.trim(),
if (s.address!.region.trim().isNotEmpty) 'region': s.address!.region.trim(),
if (s.address!.latitude != null && s.address!.longitude != null) ...{
'latitude': s.address!.latitude,
'longitude': s.address!.longitude,
},
},
'solarMode': solarModeApi[s.solarMode]!,
if (s.solarMode != SolarMode.none && pv != null) 'pvCapacityKwp': pv,
'gridConnection': gridConnectionApi[s.gridConnection]!,
if (rate != null) 'electricityRate': {'amountPerKwh': rate, 'currency': s.currency},
// No battery keys (2026-11-20): batteries are added per device on TCP after registration.
};
}
jsonEncode writes 15.0 for a double, which is a valid JSON number.
Complete request examples (illustrative)
Home in Pakistan, solar + grid. timezone is left out and
defaults to Asia/Karachi:
{
"name": "Ghori Residence",
"plantType": "RESIDENTIAL",
"countryCode": "PK",
"address": {
"formatted": "House 12, Street 4, DHA Phase 6, Karachi",
"city": "Karachi",
"region": "Sindh",
"latitude": 24.8138,
"longitude": 67.0604
},
"solarMode": "SELF_CONSUMPTION_GRID_EXPORT",
"pvCapacityKwp": 10,
"gridConnection": "GRID_CONNECTED",
"electricityRate": { "amountPerKwh": 65, "currency": "PKR" }
}
The smallest valid body. No solar, grid-connected:
{
"name": "Shop",
"plantType": "COMMERCIAL",
"countryCode": "PK",
"solarMode": "NONE",
"gridConnection": "GRID_CONNECTED"
}
Off-grid, optional fields sent as null
the way a Dart client typically does:
{
"name": "Farm Pump House",
"plantType": "INDUSTRIAL",
"countryCode": "PK",
"address": null,
"timezone": null,
"solarMode": "SELF_CONSUMPTION",
"pvCapacityKwp": 7.5,
"gridConnection": "OFF_GRID",
"electricityRate": null
}
Outside Pakistan, which must send timezone:
{
"name": "Dubai Warehouse",
"plantType": "COMMERCIAL",
"countryCode": "AE",
"timezone": "Asia/Dubai",
"solarMode": "GRID_EXPORT",
"pvCapacityKwp": 250,
"gridConnection": "GRID_CONNECTED",
"electricityRate": { "amountPerKwh": 0.38, "currency": "AED" }
}
Success: 201 Created
The body is the created plant. It echoes every stored field, so screen 12 (Plant Created) can draw its summary card from this response without another request.
Illustrative response to the first example above:
{
"plantId": "01J9Z4A1B2C3D4E5F6G7H8J9K0",
"name": "Ghori Residence",
"plantType": "RESIDENTIAL",
"countryCode": "PK",
"address": {
"formatted": "House 12, Street 4, DHA Phase 6, Karachi",
"city": "Karachi",
"region": "Sindh",
"latitude": 24.8138,
"longitude": 67.0604
},
"timezone": "Asia/Karachi",
"solarMode": "SELF_CONSUMPTION_GRID_EXPORT",
"pvCapacityKwp": 10,
"gridConnection": "GRID_CONNECTED",
"electricityRate": { "amountPerKwh": 65, "currency": "PKR" },
"hasBattery": false,
"status": "ACTIVE",
"createdAt": "2026-09-25T10:00:00.000Z",
"updatedAt": "2026-09-25T10:00:00.000Z"
}
What to expect in it:
- Optional fields that weren't answered are left out, never
null. The minimal body's response has noaddress,pvCapacityKwporelectricityRatekeys.hasBatteryis always present (derived;falseon a new plant). Render "not set" when a key is absent. - Values come back normalised: trimmed strings, upper-case
countryCodeandcurrency, canonicaltimezone, and the defaultedtimezoneforPK. Show the response values, not the form values. plantIdis a server-generated ULID. Keep it: every other plant route needs it.statusis alwaysACTIVE. The "Setup Required" badge on screen 12 isn't a server status. It means "no device claimed yet". Show it for a new plant and link it to Claim a device. Since ADR 0012 the claim only binds the serial to the plant; the app then registers the device with the TCP server over the WebSocket.- No
rolefield. The creator is always theOWNER.
What to do next:
- Go to screen 12 using the response.
- Selected plant. The new plant is not made the user's selected
plant automatically (KI-11). Call
PUT /v1/me/selected-plantwith the newplantIdto select it explicitly — seePUT /v1/me/selected-plant. Keep the newplantIdas the active plant on the device regardless, and don't block the flow on that call's result. - Plant list. If the app caches
GET /v1/plants, add the new plant or invalidate the cache. The list returns plants oldest-first, so the new one is last.
Failures
Status codes
| Status | Body | Cause | Was a plant created? | What the app should do |
|---|---|---|---|---|
201 | the plant | Success | Yes | Screen 12 |
401 | {"message":"Unauthorized"} (gateway body, not this API's envelope) | Missing, expired or invalid ID token | No: rejected before the Lambda runs | Refresh the Cognito session and retry once. If it's still 401, send the user to sign-in and keep the wizard state |
413 | error.code: "PAYLOAD_TOO_LARGE" | Decoded body over 256 KiB | No | Not reachable from the wizard's own fields; a client bug. Don't retry unchanged |
422 | error.code: "VALIDATION_FAILED" | Body failed validation (below) | No | Show the errors on the right step. Don't auto-retry the same body |
500 | error.code: "INTERNAL" | Body isn't valid JSON (KI-7), the transaction failed, or another server fault | No when the body is this API's INTERNAL envelope (the write is atomic and happens last) | Show a generic "Something went wrong" with Try again. If it repeats, it's a client JSON bug or a server problem: report it |
503 | error.code: "DEPENDENCY_UNAVAILABLE", Retry-After header | DynamoDB throttled, errored, or timed out | No | Retry with backoff honouring Retry-After; safe here since the write never committed |
other 5xx, timeout, no response | varies (e.g. a gateway {"message": …} body) | Network loss, Lambda throttled or timed out (10 s), gateway error | Unknown | See Retries and duplicates |
403 and 404 are never returned by this endpoint. 409 CONFLICT is possible in principle (since 2026-11-03,
committed, not yet deployed): the plant's PL- code collided with an existing one three times in a row. The code
sequence is atomic, so this needs a damaged sequence and is not expected. Treat it like a 500.
The error envelope
{
"error": {
"code": "VALIDATION_FAILED",
"message": "Request validation failed",
"details": {
"formErrors": [],
"fieldErrors": {
"pvCapacityKwp": ["Number must be greater than 0"],
"solarMode": ["an OFF_GRID plant cannot use an exporting solar mode"]
}
}
}
}
error.codeis the contract: branch on it. It won't change.error.messageis always the generic"Request validation failed". Don't show it to the user on its own. It's the message the user saw during the incident, and it tells them nothing.details.fieldErrorsmaps a top-level field name to a list of messages. Nested errors are reported under the parent (address,electricityRate).details.formErrorsholds errors that don't belong to one field: an unknown top-level key, or a body that isn't a JSON object (Expected object, received array).- Match on the field name, not the message text. The texts are Zod defaults plus the server's custom messages, and they can change when the server's Zod version changes. Use them for logs and debugging, and use your own copy for users.
- One exception: a missing or empty body gives
{"error":{"code":"VALIDATION_FAILED","message":"Request body is required"}}with nodetails.
Handling a 422
-
Read
details.fieldErrorsand map each key to its wizard step:Key Step / screen name,plantType,countryCode,address,timezone1 · 08 Plant Details ( timezonehas no field, so treat it as a client bug)solarMode,pvCapacityKwp2 · 09 Solar System gridConnection,electricityRate3 · 10 Grid Connection -
Go back to the earliest step that has an error, and show your own message next to each field (the suggested messages above).
-
Keep everything else the user entered.
-
If there are
formErrors, the request builder is wrong. There's nothing the user can fix, so show a generic error and log the response. -
In debug and QA builds, log the full
detailsobject.
:::caution Fixing one error can reveal another
The server checks in two passes. The cross-field rules (timezone
outside PK, PV capacity vs. solar mode, off-grid vs. exporting, the lat/long
pair) run only if no field is missing, the wrong type, or an invalid enum
value. For example, a body with gridConnection missing and a PV capacity
conflict returns only gridConnection: Required. After that's fixed, the next submit returns the
solarMode error. Range errors (0, too long, too big) and unknown keys
don't hide the cross-field rules. Validating every rule on the device
avoids this round trip.
:::
Full validation catalogue
Every server message, verbatim, from the 2026-09-25 local run described in the "How this page was verified" note at the top of this page.
| Key | Payload that triggers it | Message |
|---|---|---|
name | missing | Required |
name | "", whitespace only | String must contain at least 1 character(s) |
name | over 120 chars after trimming | String must contain at most 120 character(s) |
name | null / number | Expected string, received null / …received number |
plantType | missing | Required |
plantType | not one of the 3 values, or wrong case | Invalid enum value. Expected 'RESIDENTIAL' | 'COMMERCIAL' | 'INDUSTRIAL', received '…' |
countryCode | missing | Required |
countryCode | not 2 letters | must be an ISO 3166-1 alpha-2 code |
countryCode | 2 letters, not assigned (UK, ZZ, XK) | is not an assigned ISO 3166-1 alpha-2 code |
address | a string | Expected object, received string |
address | only one of latitude/longitude | latitude and longitude must be supplied together |
address | latitude outside -90..90 / longitude outside -180..180 | Number must be less than or equal to 90 (or …greater than or equal to -90, …180) |
address | a coordinate as a string | Expected number, received string |
address | formatted > 400, city/region > 120 chars | String must contain at most … character(s) |
address | unknown part | Unrecognized key(s) in object: '…' |
timezone | none sent and countryCode isn't PK | is required when countryCode is not PK |
timezone | not a known zone | is not an IANA time zone |
timezone | over 64 chars | String must contain at most 64 character(s) |
solarMode | missing | Required |
solarMode | not one of the 4 values, or wrong case | Invalid enum value. Expected 'NONE' | 'SELF_CONSUMPTION' | 'GRID_EXPORT' | 'SELF_CONSUMPTION_GRID_EXPORT', received '…' |
solarMode | exporting mode with OFF_GRID | an OFF_GRID plant cannot use an exporting solar mode |
pvCapacityKwp | none sent and solarMode isn't NONE | is required when solar is installed |
pvCapacityKwp | a value sent with solarMode: NONE | must be omitted when solarMode is NONE |
pvCapacityKwp | 0 or negative | Number must be greater than 0 |
pvCapacityKwp | over 100,000 | Number must be less than or equal to 100000 |
pvCapacityKwp | a string | Expected number, received string |
gridConnection | missing | Required |
gridConnection | not one of the 2 values, or wrong case | Invalid enum value. Expected 'GRID_CONNECTED' | 'OFF_GRID', received '…' |
electricityRate | a part missing (once per missing part) | Required |
electricityRate | amountPerKwh as a string | Expected number, received string |
electricityRate | amountPerKwh negative | Number must be greater than or equal to 0 |
electricityRate | currency not 3 letters | must be an ISO 4217 code |
electricityRate | unknown part | Unrecognized key(s) in object: '…' |
batteries, hasBattery, batteryCapacityKwh, batteryPowerKw, batteryBrand, batteryBrandOther | any value (retired 2026-11-20) | none — accepted and ignored |
| (formErrors) | unknown top-level key (capacityKw, batteryKwh, status, plantId, …) | Unrecognized key(s) in object: '…' |
| (formErrors) | body is an array / string / number | Expected object, received array (etc.) |
| (no details) | empty or missing body | message Request body is required |
Retries and duplicates
Since feature 004, POST /v1/plants accepts an optional Idempotency-Key
header (1-128 chars [A-Za-z0-9_-]; KI-21 is
fixed). Send one: generate a fresh key (for example a ULID or UUID) when
the user taps Create, and reuse that same key for every retry of that tap.
- Same key, same body: the server returns the stored first response
(the same
plantId), so no duplicate is created. - Same key, different body:
422 IDEMPOTENCY_KEY_REUSED. Generate a new key. - Same key while the first request is still running:
409 IDEMPOTENCY_IN_PROGRESS. Wait a second and retry with the same key. - No key (the shipped APK): the old behaviour. Every request that passes
validation creates a new plant, and names aren't unique. Before retrying
after a timeout, call
GET /v1/plantsand check the newest item'snameandcreatedAt. - Disable the Create button while the request is in flight.
- Never auto-retry in a loop. The account's Lambda concurrency is small and shared with the telemetry system, so a retry storm makes a throttle worse.
Web create and drafts
This page covers the mobile wizard, which is unchanged by feature 004.
The web console sends the same route with X-Org-Id and a different, strict
body (systemType, customer, tags, staged devices, Idempotency-Key
required). That variant and the save-and-finish-later drafts (C15) are
documented in the Plants API:
web create
and plant drafts.
A plant created on the web with a systemType (or an older plant still storing a retired UTILITY/OTHER) is still
readable by the mobile app: the server maps it to a valid mobile
plantType and solarMode.
Reporting a problem to the backend team
Include:
- the
apigw-requestidresponse header, which lets the team find the request in the API access log - the UTC time
- the full response body, especially
error.details - the request body with personal data removed (the address can be removed)
The server doesn't log the request body or the validation errors, so without the response body the backend team can't tell which field failed.
Edge cases
- No limit on plants per account. Creating many plants is allowed.
- Duplicate names are allowed, including on the same account.
- Coordinates aren't checked against the country or the address text.
- Currency isn't checked against the country.
PKwithAEDis accepted. - Plants created before 2026-09-24 (the old contract) weren't migrated.
On
GETthey may havecapacityKwand a stringaddress, and none ofplantType,countryCode,solarMode,gridConnection. (hasBatteryis always present now — derived from the plant's devices.) Treat every wizard field as optional when reading a plant. See Plants → Edge cases. - Nothing can edit a plant yet. There's no update endpoint, so a
mistake in the wizard can't be corrected after
201. Show a review step before Create if the design allows it.
Related
- Plants API: list and detail endpoints
- Plant devices (binding): claim the plant's first device ("Setup Required"), then register it with TCP over the WebSocket (ADR 0012)
- Plants → ownership, share and unshare: who owns a plant and how it changes
CreatePlantInputschema- Known issues: KI-7, KI-11, KI-21