Checkout fields and country address rules
The checkout form as editable rows, and the per-country address rules the form and the documents follow.
The checkout form as rows a merchant edits and an add-on adds to, and the per-country address rules behind it. See Checkout fields and Countries and addresses.
List the checkout fields
/api/v1/kahunacart/checkout-fields
Every field the checkout form draws, in the order it draws them, with the three condition documents that decide when each is required, when it is hidden and what a valid answer is — plus the attribute vocabulary those conditions may be written against. Fields owned by core are the shipped checkout: they can be reordered, relabelled, required, hidden or turned off, and they cannot be deleted. Read this before writing any condition; an attribute not on the published list is refused by name rather than quietly matching nothing.
Add a checkout field
/api/v1/kahunacart/checkout-fields
Add a field to the checkout form. The key is lowercase snake_case, or vendor/name for an add-on's own, and it is what the answer is stored under on every order. required, hidden and validation are condition documents in KahunaCart's own condition language — the same one sales, coupons and payment methods use — written against the attributes list_checkout_fields publishes; a validation document also needs a message_key saying what to tell a customer whose answer is refused. Null means the condition is absent, so a null required is never required; a container with no children is always true, so an empty required is always required.
Parameters
| Name | Type | Description |
|---|---|---|
| key required | string | Lowercase snake_case, or vendor/name for an add-on: vat_number, acme/delivery_date |
| label_key required | string | A PLUGIN_*.* language key. Never English — a checkout that cannot be translated is a checkout for one country. |
| type optional | string |
Which control draws it. `country` and `region` are the two the shipped address form uses.
One of:
text, textarea, email, tel, select, checkbox, date, number, country, regionDefault:
text |
| section optional | string |
Which fieldset it belongs in.
One of:
contact, billing, shipping, orderDefault:
order |
| position optional | integer | Order within the section; lower draws first. The shipped fields are spaced by ten. |
| options optional | array of object | For a select: [{value, label_key}]. Keys: `value`, `label_key` |
| required optional | object | A condition document. Null is never required; a container with no children is always. |
| hidden optional | object | A condition document. Null is never hidden. A field hidden here is refused if it is posted. |
| validation optional | object | A condition document that holds when the answer is good, plus a `message_key` for when it is not. |
| enabled optional | boolean |
Whether the form draws it.
Default:
true |
Change a checkout field
/api/v1/kahunacart/checkout-fields/{id}
Change a checkout field. Only the fields you send are written. A core field can be reordered, relabelled, required, hidden or turned off like any other — what it cannot be is deleted. Sending null for required, hidden or validation clears that condition.
Parameters
| Name | Type | Description |
|---|---|---|
| id required | integer | The field to change. |
| key optional | string | |
| label_key optional | string | |
| type optional | string |
One of:
text, textarea, email, tel, select, checkbox, date, number, country, region |
| section optional | string |
One of:
contact, billing, shipping, order |
| position optional | integer | |
| options optional | array of object | Keys: `value`, `label_key` |
| required optional | object or null | |
| hidden optional | object or null | |
| validation optional | object or null | |
| enabled optional | boolean |
Delete a checkout field
/api/v1/kahunacart/checkout-fields/{id}
Delete a field a merchant or an add-on added. A core field is refused with a 409 and a sentence saying to turn it off instead: the shipped checkout is expressed in those rows, and a store that deleted billing_city would be a store that cannot take an address. Answers on every order that already carry the field keep their value and their label, because an order records what happened rather than what the store currently asks.
Parameters
| Name | Type | Description |
|---|---|---|
| id required | integer | The field to delete. |
Read a country's address rules
/api/v1/kahunacart/countries/{code}/locale
What one country expects of a postal address: the layout it prints in, the postcode grammar, the phone grammar and which address fields it will not do without. A country nobody has seeded answers the generic rules rather than a 404, which is exactly what checkout uses for it, so this is never an error. effective_address_format is the layout that would actually be used — the row's own, else the shipped table, else the default — while address_format is only what the row itself carries.
Parameters
| Name | Type | Description |
|---|---|---|
| code required | string | ISO 3166-1 alpha-2, e.g. DE |
Correct a country's address rules
/api/v1/kahunacart/countries/{code}/locale
Fix one country without waiting for a release. A postcode pattern that refuses valid post, a required-field set that insists on a postcode in a country that has none, an address printing in the wrong order on an invoice — each is one row here. Patterns are regular expressions without delimiters, matched case-insensitively; an empty pattern accepts anything, including nothing. Clearing address_format puts the shipped layout back. restore: true returns every value to what this release ships. Nothing here affects any other country.
Parameters
| Name | Type | Description |
|---|---|---|
| code required | string | ISO 3166-1 alpha-2, e.g. DE |
| address_format optional | string or null | A token list, one line per line: {name}, {company}, {address1}, {address2}, {city}, {region}, {region_code}, {postcode}, {country}. Empty restores the shipped layout. |
| postcode_pattern optional | string or null | A regular expression without delimiters, e.g. ^\d{5}$. Empty accepts anything. |
| phone_pattern optional | string or null | The same, for a phone number. The shipped patterns are a format check rather than a numbering plan. |
| required_fields optional | array of string or null | Which address fields this country needs. Null restores the generic set. |
| enabled optional | boolean | Whether the country is offered at checkout at all. |
| restore optional | boolean |
Put every value back to what this release ships, ignoring everything else in the body.
Default:
false |
Look up an address
/api/v1/kahunacart/address-lookup
Suggestions for an admin address form as it is typed, or the full address for the one picked, from the Mapbox or Google key under Address Validation. The same answer as the storefront's {base}/address-lookup, counted against the same daily allowance. The key never reaches the browser. No tool: it serves a form being typed into.
The list route carries the condition vocabulary beside the fields, and that vocabulary is closed: an attribute nobody publishes is refused by name when the field is saved rather than ignored when it runs. required, hidden and validation are each a condition document in the same rule language as sales and coupons, and null and an empty container mean different things: null is never, an empty container is always. A core field can be reordered, relabelled, required, hidden or switched off but answers a delete with a 409, because the shipped checkout is expressed in those rows. label_key is a language key; English in a label is refused.
The locale routes are keyed by ISO 3166-1 alpha-2 code. A country with no row answers the read with the generic values rather than a 404, which is what checkout would actually use for it, and the first save creates the row. restore: true puts the shipped values back, including clearing an address format you have typed over. A postcode or phone pattern that will not compile is refused when you save it, and would be ignored at checkout if it ever got there.