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

ParameterTypeRequiredDescription
idPositive integerYesActive invoice ID.
customer_idPositive integerYesCustomer or asset ID.
customer_typeIntegerNoDefaults 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

ResponseCondition
{"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_details at the invoice date, marks the resolved customer as having invoices, advances last_edited, and fires Invoice_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