Customers
Total stock used for a customer, asset, or location
/a/Customer_stockTotalsGetData
Sum stock quantities for completed jobs targeted to a customer, asset, or location while excluding main entries marked with the “None” source.
When to use this endpoint
Use Customer_stockTotalsGetData for the CRM2 Customer Stock and Asset Stock summary tables.
For CRM1-compatible totals that include legacy “None” source entries, use Customer_stockTotalsGet.
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 target ID. Existence of the customer, asset, or location is not checked. |
customerType | Integer string | No | Job target type: 0 customer (default), 1 asset, or 2 location. Other integer values are accepted but normally find no rows. |
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 0 to omit stock embedded in eligible table-form fields; CRM2 sends 0. |
Example request
$totals = FM_api('Customer_stockTotalsGetData', [
'id' => '1088',
'customerType' => '0',
'includeForm' => '0',
'dateFrom' => '2026-09-01',
'dateTo' => '2026-09-30',
]);
Example response
{
"Filter cartridge": 5,
"Cable 10m": 2.5
}
The result is keyed by current stock name, not ID. No matches return an empty JSON array ([]) rather than an empty object because the PHP result begins as an empty array.
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 completion state, match both target ID and
customerType, and have metadatauses_stock=1. - Main
stock_usedentries whosesourcebegins with-1are skipped. This regression behavior prevents the stock picker’s “None” sub-status from contributing to totals. - The source exclusion is applied while reading main stock. Table-form entries are appended later and are not passed through that same source check.
- Table-form extraction runs only when main
stock_useddecodes to a nonempty array and only for fields whose current form definition isstockorstock-single. - There is no pagination or explicit ordering. Missing stock IDs can become an empty-string name key.
See it in Fieldmotion
CRM1
A source search found no CRM1 caller for this newer totals variant. CRM1 uses Customer_stockTotalsGet.
CRM2
Open Customer Stock or Asset Stock and filter Network requests for Customer_stockTotalsGetData. Customer pages use the default target type; asset pages send customerType=1. Both currently send includeForm=0.
Related endpoints
Customer_stockTotalsGetis the CRM1 variant and includes main “None” source entries.Customer_stockGetExportDataprovides row-level export data for both CRM1 and CRM2.