Skip to main content

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. batteries and the flat hasBattery / batteryCapacityKwh / batteryPowerKw / batteryBrand / batteryBrandOther are accepted with any value and ignored — never a 422, 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 on plant.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 hasBattery stays derived: true only once a device bound to the plant has a battery on TCP (false on 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.

#MistakeWhat the server saysFix
1A number typed into a text field is sent as a string ("15")Expected number, received stringdouble.tryParse(text.trim()), send the double, or leave the key out when it's null
2pvCapacityKwp: 0 sent as "no value"Number must be greater than 0Leave the key out (or send null). 0 is a value, and it's invalid
3(retired 2026-11-20) battery fieldsnone — batteries and the flat battery fields are now accepted with any value and ignoredStop sending them; add batteries on TCP after registering the inverter
4An 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
5An old-contract or misspelled key (capacityKw, batteryKwh, a string address)Unrecognized key(s) in object: '…' / Expected object, received stringBuild 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> and Content-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 owner ownerUserSub).
  • What the server does: it validates the body, then writes the plant and the caller's OWNER membership 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. 15 and 15.5 are fine. "15" is a 422. Decimals are accepted and stored as sent (no rounding).
  • Enums are exact, upper-case strings. "residential" is a 422.
  • "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 default null-emitting serialisers are fine, so you don't need includeIfNull: false.
  • null on a required field is a 422 (Expected string, received null).
  • Strings are trimmed before length checks, and stored trimmed.
  • Unknown keys are rejected at the top level, inside address and inside electricityRate. This includes server-owned fields: don't send plantId, status, createdAt or role.

Step 1 · Screen 08 · Plant Details​

name (Plant Name)​

Typestring
RequiredYes
ValidationTrimmed, then 1-120 characters. Whitespace-only is empty
UniquenessNone. Two plants may have the same name, including on the same account
PayloadServer error on nameSuggested message
key missingRequired"Enter a name for your plant."
"" or " "String must contain at least 1 character(s)"Enter a name for your plant."
121+ charactersString must contain at most 120 character(s)"Plant name can be at most 120 characters."
nullExpected 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)​

ValueMeaning
RESIDENTIALA home
COMMERCIALA shop, office or other business premises
INDUSTRIALA 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).

PayloadServer error on plantType
key missingRequired
"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)​

Typestring, ISO 3166-1 alpha-2 (PK, AE, GB, …)
RequiredYes
ValidationExactly 2 letters, then checked against the 249 assigned codes. Case-insensitive; stored upper-case ("pk" → "PK")
Rejected on purposeUK (use GB), ZZ, XK (Kosovo; user-assigned, not an official code)
Side effectDecides whether timezone is required (see timezone)
PayloadServer error(s)
key missingcountryCode: 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.

PartTypeValidationSource on the screen
formattedstringTrimmed, ≤ 400 charsFull address line
citystringTrimmed, ≤ 120 chars
regionstringTrimmed, ≤ 120 charsProvince / state
latitudenumber-90 to 90"Use current location" / "Pick on map"
longitudenumber-180 to 180"Use current location" / "Pick on map"
  • latitude and longitude go 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 contain address.
  • The address is an object. A plain string ("address": "Lahore") is the old contract and returns a 422.
  • The server doesn't geocode or cross-check anything. It doesn't check that the coordinates are in countryCode, or that city matches them.
PayloadServer error on addressSuggested 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.

countryCodetimezone sent?Result
PKno / null / ""✅ Stored as Asia/Karachi
PK"Asia/Karachi" (or any valid zone)✅ Stored as sent
anything elseno / null / ""❌ timezone: is required when countryCode is not PK
anything elsea valid IANA zone, e.g. "Asia/Dubai"✅ Stored
  • Validation: ≤ 64 characters, matched case-insensitively against Intl.supportedValuesOf('timeZone') plus the literal UTC (KI-19 fixed). Stored in canonical case ("asia/karachi" → "Asia/Karachi"). Rejected with 422 (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" with timezone: "Asia/Karachi" is accepted.
  • Send an IANA name (Area/City), or UTC. Nothing else validates.
  • For a non-PK plant, fill timezone in without asking the user. Either read the device's IANA zone (for example with the flutter_timezone package) 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)MeaningAllowed with OFF_GRID?pvCapacityKwp
NONENo solar panels installed✅Must be omitted
SELF_CONSUMPTIONSolar powers the site, nothing is sold to the utility✅Required
GRID_EXPORTSolar is exported (sold) to the utility❌Required
SELF_CONSUMPTION_GRID_EXPORTSolar powers the site and the surplus is exported❌Required

Required, exactly one, case-sensitive.

PayloadServer error on solarMode
key missingRequired
"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)​

TypeJSON number, kWp (kilowatt-peak)
MeaningThe panels' total DC rating, not the inverter's rating
RequiredYes when solarMode isn't NONE. Must be left out (or null/"") when solarMode is NONE
Validation> 0 and ≤ 100,000. Decimals allowed (5.25)
PayloadServer error on pvCapacityKwpSuggested message
missing / null / "" with solar installedis required when solar is installed"Enter your installed solar capacity."
0, -1Number must be greater than 0"Capacity must be more than 0 kWp."
100001Number 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 NONE is picked, and make it required then.
  • When the user switches to NONE, clear any capacity already typed. A stale value left in state is a 422.
  • Use a numeric keyboard (TextInputType.numberWithOptions(decimal: true)) and parse with double.tryParse. If the locale may type 1,000 or 5,5, normalise the separators first: double.tryParse("1,000") is null.

Step 3 · Screen 10 · Grid Connection​

gridConnection​

ValueMeaning
GRID_CONNECTEDThe site is connected to the utility grid
OFF_GRIDThe 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 choiceUser picks OFF_GRID on screen 10What the app should do
NONE or SELF_CONSUMPTIONfineNothing
GRID_EXPORT or SELF_CONSUMPTION_GRID_EXPORTconflictShow 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.

PartTypeRequired (if the object is sent)Validation
amountPerKwhJSON numberYes≥ 0 and ≤ 100,000. 0 is allowed
currencystringYesExactly 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 a 422 (Required once for each missing part).
  • If the user typed an amount, send the object with both parts. Take currency from the country (e.g. PK → PKR) unless the design lets the user pick it.
  • It isn't restricted by gridConnection: an OFF_GRID plant may still send a rate.
PayloadServer error on electricityRateSuggested 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:

  1. POST /v1/plants (this page) → keep the plantId.
  2. Register the inverter into the plant over the TCP WebSocket (register with the plantId) — see the TCP server's device registration guide.
  3. 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 no address, pvCapacityKwp or electricityRate keys. hasBattery is always present (derived; false on a new plant). Render "not set" when a key is absent.
  • Values come back normalised: trimmed strings, upper-case countryCode and currency, canonical timezone, and the defaulted timezone for PK. Show the response values, not the form values.
  • plantId is a server-generated ULID. Keep it: every other plant route needs it.
  • status is always ACTIVE. 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 role field. The creator is always the OWNER.

What to do next:

  1. Go to screen 12 using the response.
  2. Selected plant. The new plant is not made the user's selected plant automatically (KI-11). Call PUT /v1/me/selected-plant with the new plantId to select it explicitly — see PUT /v1/me/selected-plant. Keep the new plantId as the active plant on the device regardless, and don't block the flow on that call's result.
  3. 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​

StatusBodyCauseWas a plant created?What the app should do
201the plantSuccessYesScreen 12
401{"message":"Unauthorized"} (gateway body, not this API's envelope)Missing, expired or invalid ID tokenNo: rejected before the Lambda runsRefresh the Cognito session and retry once. If it's still 401, send the user to sign-in and keep the wizard state
413error.code: "PAYLOAD_TOO_LARGE"Decoded body over 256 KiBNoNot reachable from the wizard's own fields; a client bug. Don't retry unchanged
422error.code: "VALIDATION_FAILED"Body failed validation (below)NoShow the errors on the right step. Don't auto-retry the same body
500error.code: "INTERNAL"Body isn't valid JSON (KI-7), the transaction failed, or another server faultNo 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
503error.code: "DEPENDENCY_UNAVAILABLE", Retry-After headerDynamoDB throttled, errored, or timed outNoRetry with backoff honouring Retry-After; safe here since the write never committed
other 5xx, timeout, no responsevaries (e.g. a gateway {"message": …} body)Network loss, Lambda throttled or timed out (10 s), gateway errorUnknownSee 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.code is the contract: branch on it. It won't change.
  • error.message is 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.fieldErrors maps a top-level field name to a list of messages. Nested errors are reported under the parent (address, electricityRate).
  • details.formErrors holds 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 no details.

Handling a 422​

  1. Read details.fieldErrors and map each key to its wizard step:

    KeyStep / screen
    name, plantType, countryCode, address, timezone1 · 08 Plant Details (timezone has no field, so treat it as a client bug)
    solarMode, pvCapacityKwp2 · 09 Solar System
    gridConnection, electricityRate3 · 10 Grid Connection
  2. Go back to the earliest step that has an error, and show your own message next to each field (the suggested messages above).

  3. Keep everything else the user entered.

  4. 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.

  5. In debug and QA builds, log the full details object.

:::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.

KeyPayload that triggers itMessage
namemissingRequired
name"", whitespace onlyString must contain at least 1 character(s)
nameover 120 chars after trimmingString must contain at most 120 character(s)
namenull / numberExpected string, received null / …received number
plantTypemissingRequired
plantTypenot one of the 3 values, or wrong caseInvalid enum value. Expected 'RESIDENTIAL' | 'COMMERCIAL' | 'INDUSTRIAL', received '…'
countryCodemissingRequired
countryCodenot 2 lettersmust be an ISO 3166-1 alpha-2 code
countryCode2 letters, not assigned (UK, ZZ, XK)is not an assigned ISO 3166-1 alpha-2 code
addressa stringExpected object, received string
addressonly one of latitude/longitudelatitude and longitude must be supplied together
addresslatitude outside -90..90 / longitude outside -180..180Number must be less than or equal to 90 (or …greater than or equal to -90, …180)
addressa coordinate as a stringExpected number, received string
addressformatted > 400, city/region > 120 charsString must contain at most … character(s)
addressunknown partUnrecognized key(s) in object: '…'
timezonenone sent and countryCode isn't PKis required when countryCode is not PK
timezonenot a known zoneis not an IANA time zone
timezoneover 64 charsString must contain at most 64 character(s)
solarModemissingRequired
solarModenot one of the 4 values, or wrong caseInvalid enum value. Expected 'NONE' | 'SELF_CONSUMPTION' | 'GRID_EXPORT' | 'SELF_CONSUMPTION_GRID_EXPORT', received '…'
solarModeexporting mode with OFF_GRIDan OFF_GRID plant cannot use an exporting solar mode
pvCapacityKwpnone sent and solarMode isn't NONEis required when solar is installed
pvCapacityKwpa value sent with solarMode: NONEmust be omitted when solarMode is NONE
pvCapacityKwp0 or negativeNumber must be greater than 0
pvCapacityKwpover 100,000Number must be less than or equal to 100000
pvCapacityKwpa stringExpected number, received string
gridConnectionmissingRequired
gridConnectionnot one of the 2 values, or wrong caseInvalid enum value. Expected 'GRID_CONNECTED' | 'OFF_GRID', received '…'
electricityRatea part missing (once per missing part)Required
electricityRateamountPerKwh as a stringExpected number, received string
electricityRateamountPerKwh negativeNumber must be greater than or equal to 0
electricityRatecurrency not 3 lettersmust be an ISO 4217 code
electricityRateunknown partUnrecognized key(s) in object: '…'
batteries, hasBattery, batteryCapacityKwh, batteryPowerKw, batteryBrand, batteryBrandOtherany 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 / numberExpected object, received array (etc.)
(no details)empty or missing bodymessage 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/plants and check the newest item's name and createdAt.
  • 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-requestid response 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. PK with AED is accepted.
  • Plants created before 2026-09-24 (the old contract) weren't migrated. On GET they may have capacityKw and a string address, and none of plantType, countryCode, solarMode, gridConnection. (hasBattery is 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.