Customers
Total stock used for a customer
/a/Customer_stockTotalsGet
Sum stock quantities from completed direct-customer jobs and return a name-to-quantity object for the CRM1 Stock Used summary.
When to use this endpoint
Use Customer_stockTotalsGet for the CRM1 customer Stock Used totals shown beneath the job table.
Use Customer_stockTotalsGetData for CRM2, asset targets, or exclusion of main stock entries whose source represents “None”.
Authentication and permissions
The request must authenticate with signed API-key fields or a logged-in CRM session. The handler performs no additional page or role-permission check.
The lookup and any write use the authenticated tenant; an ID from another tenant cannot be addressed through this call.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Integer string | Yes | Positive customer ID. The customer row is not checked for existence. |
dateFrom | Date/time string | No | Inclusive completed-time lower bound converted from tenant-local time to epoch. May be supplied independently. |
dateTo | Date string | No | Inclusive tenant-local completed-time upper bound through 23:59:59. May be supplied independently. |
includeForm | Integer string | No | Defaults to enabled. Set exact integer-like 0 to omit stock embedded in eligible table-form fields. |
Example request
$totals = FM_api('Customer_stockTotalsGet', [
'id' => '1088',
'dateFrom' => '2026-09-01',
'dateTo' => '2026-09-30',
]);
Example response
{
"Filter cartridge": 5,
"Cable 10m": 2.5
}
The JSON object is keyed by each stock row’s current name, not stock ID. Quantities are sums of stored amt values and can be integers, decimals, or numeric strings coerced by PHP addition. No matches encode as an empty JSON array ([]), not an empty object.
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":"missing or invalid parameter: id"} | id is absent, zero, negative, or non-numeric. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Jobs must be non-deleted, have non-zero
is_complete, target the customer directly (customer_type=0), and have metadatauses_stock=1. - The endpoint starts table-form extraction only when the job’s main
stock_usedvalue decodes to a nonempty array. A job with stock only in subforms contributes nothing. - When form stock is enabled, only fields whose saved form definition still identifies them as
stockorstock-singleare read. - Main stock entries whose
sourcestarts with-1are included by this older endpoint. The newer data variant excludes them. - There is no pagination or ordering. Missing/deleted stock records can produce an empty-string object key.
See it in Fieldmotion
CRM1
Open a customer’s Stock Used tab. Filter Network requests for Customer_stockTotalsGet; opening the page and changing its date range refresh the summary object.
CRM2
CRM2 does not call this older endpoint; its customer and asset pages use Customer_stockTotalsGetData with includeForm=0.
Related endpoints
Customer_stockTotalsGetDataadds target-type support and excludes main “None” source entries.Customer_stockGetDTreturns the contributing customer jobs and raw stock payloads.Customer_stockExportTotalsdownloads a CSV but uses materially different inclusion rules.