Customers
Set a customer postcode
/a/Customer_setPostCode
Change or clear one customer postcode while attempting to update address history and dependent caches.
When to use this endpoint
Use Customer_setPostCode for a focused postcode correction after resolving the customer ID.
The endpoint treats the postcode as text and does not normalize country-specific spacing or case.
Authentication and permissions
The request must authenticate with signed API-key fields or a logged-in CRM session. The handler performs no additional page or role-permission check.
The lookup and any write use the authenticated tenant; an ID from another tenant cannot be addressed through this call.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer string | Yes | Customer to update; it must convert to a positive integer. |
val | String | Yes | New postcode, trimmed before comparison and storage. Present blank clears it. The setter itself imposes no maximum length. |
Example request
$result = FM_api('Customer_setPostCode', [
'id' => '1088',
'val' => 'BT1 1AA',
]);
Example response
{
"ok": 1
}
An unchanged trimmed postcode returns {"ok":1,"msg":"no change needed"}.
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"not logged in"} | No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs. |
{"error":"missing or invalid parameter: id"} | id is absent or invalid. |
{"error":"missing or invalid parameter: val"} | val was omitted. |
{"error":"customer does not exist"} | No matching customer row exists. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- The customer lookup has no active/deleted filter.
- No postcode syntax, casing, or country relationship is validated by the final setter.
- The helper runs before the final write and the two operations are not transactional.
- This is a single-record mutation; it provides no list filtering or pagination.
Side effects
- The helper can update address history, clear cached customer details on linked non-deleted jobs and invoices, and mark this customer and descendants as edited.
- The final write updates
postcode,last_edited, andedited_uuid, invalidates the customer cache, logs the edit, and firesCustomer_edit.
See it in Fieldmotion
CRM1
Open the legacy customer edit popup, change Postcode, and filter Network requests for Customer_setPostCode.
CRM2
No direct production CRM2 caller was found. CRM2 uses its layout-driven address update.
Related endpoints
Customer_getAddressreturns the assembled address and historical variants.Customer_getretrieves the current customer row.