Invoices
Set an invoice custom field
POST
/a/Invoice_setField
Set one custom invoice-form value in the stored form_fields JSON object.
When to use this endpoint
Use this for a single CRM1 custom-form field. Use Invoice_updateData for CRM2 mapped layout saves.
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 | Integer | Yes | Active invoice ID. |
key | String | Yes | JSON object key; it is not checked against the selected invoice form. |
val | Mixed | Yes | Value assigned to that key. |
Example request
$result = FM_api('Invoice_setField', ['id' => 981, 'key' => '42', 'val' => 'Reference text']);
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":"id, key, val parameters all required"} | Any key is absent. |
{"error":"cannot edit invoices that are marked Paid"} | The invoice is Paid. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Malformed/non-array stored JSON is replaced with a new object. An identical existing value returns
warning: no change required.
Side effects
- Rewrites the complete
form_fieldsJSON value, advanceslast_edited, and firesInvoice_edit.
See it in Fieldmotion
CRM1
The invoice editor uses this route for custom invoice-form controls.
CRM2
No direct production CRM2 caller was found for this route.
Related endpoints
Invoices_getDataTablesupplies paginated CRM2 invoice rows and IDs.Invoices_getDTis the CRM1 invoice-list counterpart.