When to use this endpoint

Use Customer_stockGetDT for the paged CRM1 Stock Used tab when each row must remain tied to a completed job and assigned user.

Use Customer_stockTotalsGet when only quantities aggregated by stock name are needed.

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

ParameterTypeRequiredDescription
cidInteger stringYesCustomer ID. Presence is validated, but positivity and customer existence are not. Only direct-customer jobs are queried.
startInteger stringYesZero-based row offset.
lengthInteger stringYesPage size.
drawInteger stringNoDataTables counter copied to the response; defaults to 0.
dateFromDate/time stringNoInclusive completed-time lower bound converted from tenant-local time to epoch. When present, dateTo is also consumed.
dateToDate stringWith dateFromInclusive tenant-local completed-time upper bound through 23:59:59. It has no effect without dateFrom.
job_idInteger stringNoExact job ID. Zero and blank do not filter.
stockStringNoFind stock IDs whose name, code, or description contains this text, then match those IDs inside the job’s main stock_used JSON text. Table-form stock is not searched by this filter.
usernameStringNoFind assigned user IDs whose name contains this text. No matching user forces an empty result.

Example request

$rows = FM_api('Customer_stockGetDT', [
	'cid' => '1088',
	'start' => '0',
	'length' => '25',
	'draw' => '14',
	'dateFrom' => '2026-09-01',
	'dateTo' => '2026-09-30',
	'username' => 'Aoife',
	'stock' => 'filter',
]);

Example response

{
  "draw": 14,
  "recordsTotal": 3,
  "recordsFiltered": 1,
  "data": [
    ["7204", 1727175600, "36", [[{"id":"211","amt":"2","cost":12.5}], {"id":"212","amt":"1"}]]
  ]
}

Each row is job ID, completed-time epoch as an integer or blank string, user ID, and a heterogeneous stock array. Main stock_used is appended as one decoded array; stock found in table-form fields is appended item by item.

The exact stock objects preserve their stored fields, which can include id, amt, containers, cost, source, and link metadata.

Errors and unusual responses

ResponseCondition
{"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: start"}start is absent.
{"error":"missing or invalid parameter: length"}length is absent.
{"error":"missing or invalid parameter: cid"}cid is absent.

Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.

Behaviour and edge cases

  • Rows require a non-zero completion state, customer_type=0, the requested customer ID, and a non-deleted job. They are always ordered by completion epoch descending; request ordering fields are ignored.
  • Table-form extraction walks every encoded field containing a stock member and does not consult the form definition or field type. Malformed JSON is skipped or can generate legacy warnings depending on its shape.
  • The active value sent by CRM1 is not read. Customer activity and deletion state are not checked.

See it in Fieldmotion

CRM1

Open a customer and select Stock Used. Filter Network requests for Customer_stockGetDT; date, job ID, user-name, stock-text, and paging controls reload the table. CRM1 also sends active, which the handler ignores.

CRM2

CRM2 does not call this endpoint for its Stock Used table; it uses a newer CustomersStock_getDataTable flow and calls other endpoints in this family for totals and export retrieval.

Related endpoints