Invoices
Set an invoice period end
POST
/a/Invoice_setToDate
Store the invoice-period end value in invoice metadata.
When to use this endpoint
Use this with Invoice_setFromDate for the date range printed on an 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 | Invoice ID. |
val | Mixed | Yes | Stored unchanged as meta.invoice_to; no date validation is performed. |
Example request
$result = FM_api('Invoice_setToDate', ['id' => 981, 'val' => '2026-09-30']);
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":"invoice does not exist"} | The invoice is absent or deleted. |
{"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 invoice metadata is treated as an empty object before storing the period value.
Side effects
- Rewrites invoice metadata, advances edit metadata, and fires
Invoice_edit.
See it in Fieldmotion
CRM1
The main invoice editor’s period controls 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.