Invoices
Set an invoice discount
POST
/a/Invoice_setDiscount
Set an unpaid invoice discount value and recalculate stored totals from its line items.
When to use this endpoint
Use this legacy setter when editing the invoice-wide discount independently of the CRM2 mapped form.
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. |
val | Numeric-compatible scalar | Yes | Discount value. Loose PHP numeric comparison accepts ordinary numeric strings. |
Example request
$result = FM_api('Invoice_setDiscount', ['id' => 981, 'val' => '10']);
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":"invalid discount"} | The value does not pass the legacy numeric comparison. |
{"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 value returns
warning: no change needed. - The endpoint uses the legacy
discountcolumn; CRM2 layout migration can reinterpret old absolute discounts as percentages.
Side effects
- Writes the discount, recalculates net/gross totals under the invoice row lock, advances edit metadata, updates linked job totals, and fires
Invoice_edit.
See it in Fieldmotion
CRM1
The main invoice editor exposes this invoice-wide discount control.
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.