Invoices
Set an invoice form
POST
/a/Invoice_setForm
Change the invoice form used to render an unpaid invoice.
When to use this endpoint
Use this when selecting a different invoice template/form without changing field values.
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. |
val | Integer | Yes | Form ID. Zero clears the selection; positive IDs must exist and have form type 7. |
Example request
$result = FM_api('Invoice_setForm', ['id' => 981, 'val' => 17]);
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":"form does not exist"} | A positive form ID is absent. |
{"error":"wrong form type"} | The selected form is not an Invoice form. |
{"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
- An unchanged form returns
warning: no change needed. The route does not clear or translate existing custom-form values.
Side effects
- Updates
form_idandlast_edited. It does not fireInvoice_edit.
See it in Fieldmotion
CRM1
Job Invoice and the main invoice editor call this route.
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.