Invoices
Set an invoice customer or asset
POST
/a/Invoice_setCustomer
Change an unpaid invoice’s customer or asset target and rebuild its historical address snapshot.
When to use this endpoint
Use this to correct the billed target without recreating the invoice.
Authentication and permissions
The request must use a logged-in CRM session or valid signed API credentials and is scoped to that tenant.
Users whose legacy crm_access mask contains bit 64 receive {"error":"no permission to access api"}. No record-owner check is made.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Positive integer | Yes | Active invoice ID. |
customer_id | Positive integer | Yes | Customer or asset ID. |
customer_type | Integer | No | Defaults to 0 for customer. Type 1 stores the asset as target and resolves its owner as the invoice customer. |
Example request
$result = FM_api('Invoice_setCustomer', ['id' => 981, 'customer_id' => 1042, 'customer_type' => 0]);
Example response
{
"ok": 1
}
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":"cannot edit invoices that are marked Paid"} | The invoice status is 2. |
{"error":"invoice does not exist"} | The invoice is absent or deleted. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- An asset without an owner is stored with customer ID 0 while retaining the asset target. The handler does not independently verify customer/asset existence.
- An unchanged resolved target returns success with
warning: no change necessary.
Side effects
- Rebuilds
customer_detailsat the invoice date, marks the resolved customer as having invoices, advanceslast_edited, and firesInvoice_edit.
See it in Fieldmotion
CRM1
The main invoice editor and customer-type enforcement widget call this route.
CRM2
The QuickBooks connection widget can use this route to correct an invoice target.
Related endpoints
Invoices_getDataTablesupplies paginated CRM2 invoice rows and IDs.Invoices_getDTis the CRM1 invoice-list counterpart.