Customers
Set a customer country
/a/Customer_setCountry
Change or clear the short country value on one customer while attempting to update address history.
When to use this endpoint
Use Customer_setCountry for a focused country-code correction on a known customer address.
Prefer a consistent three-letter country convention in integrations. The endpoint limits length but does not prove the value is an ISO code.
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 | No | Trimmed country value, at most 3 bytes. Omission and blank both clear the field. Any value of 0–3 bytes is accepted by this setter. |
Example request
$result = FM_api('Customer_setCountry', [
'id' => '1088',
'val' => 'GBR',
]);
Example response
{
"ok": 1
}
An unchanged trimmed value 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":"invalid country code"} | The trimmed value is longer than 3 bytes. |
{"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 setter does not uppercase the value or validate it against a country list.
- The customer lookup has no active/deleted filter.
Address_setruns before the final field update, outside a transaction, and its errors are not returned.- This is a single-record mutation; it provides no list filtering or pagination.
Side effects
- The address helper can update address history, clear linked non-deleted job and invoice customer-detail caches, and mark this customer and descendants as edited.
- The final write updates
country,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 Country, and filter Network requests for Customer_setCountry.
CRM2
No direct production CRM2 caller was found. CRM2 uses its mapped layout update for customer addresses.
Related endpoints
Customer_getAddressexposes current and historical address context.Customer_newapplies the tenant default country when creation omits one.