Stock exports and reporting
Export allocation batch details
/a/Stock_exportAllocates
Download allocation rows expanded by their inventory provenance.
When to use this endpoint
Use for batch-level stock allocated to jobs, users, vehicles, quotes and customers. This is a snapshot rather than a movement ledger.
Authentication and permissions
Authenticate with a signed API-key request or a logged-in CRM session. Requires Stock view (pageStocks_view) and table export (pageMain_exportTableData) permissions through the shared export guard; denial returns permission denied.
Client administrators and the all permission satisfy the checks. Legacy users with no role use the helper’s allow fallback when no explicit permission list is loaded. This is not merely the CRM1 export-button bit check.
Queries use the authenticated tenant. No department/owner restriction or stock-tracking feature gate is added by these handlers. CRM2 features2.stockTracking changes the export choices offered, not server authorization. Session CSRF and API signing still apply.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
stockIDsFilter | Comma-separated string | No | A string such as 1042,1088, not a JSON or native array. Omitted or blank/whitespace means no selection restriction. Tokens must be positive decimal IDs; whitespace is trimmed and duplicates are removed. Malformed, zero/negative or non-string lists return invalid parameter: stockIDsFilter. |
Example request
$csv = FM_api('Stock_exportAllocates', ['stockIDsFilter'=>'1042']);
Example response
ID,"Part Number",Description,"Manufacturer/Supplier Part Number",Type,Allocate,"Supplier Name",Cost,QTY,"Total Cost",Batch
1042,FLT-01,"Replacement cartridge",AC-01,Job,2042,"Parts supplier",4.5,2,9,BATCH-01
Success is raw CSV, not JSON: retain the response body instead of JSON-decoding it. The response uses text/csv and the final download filename stock_allocate.csv. Column positions and blank cells are meaningful.
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":"permission denied"} | Either required export permission is denied. |
Header-only CSV or interrupted output | Most database reads are not checked for failure. A blank export is not proof that the database contained no matching rows; malformed stored JSON can interrupt legacy reports. |
{"error":"invalid parameter: stockIDsFilter"} | A supplied selected-ID list is not a string of positive decimal IDs. |
{"error":"invalid parameter: search"} | A supplied stock/date filter is an array or other non-scalar value; the error names that parameter. |
{"error":"could not create stock export"} | The per-request CSV stream cannot be created, written or rewound. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Reads container types 7,1,2,12,6 for non-deleted stock, with no amount>0 guard. Archived stock remains included; related suppliers/storages/owners have no deleted filter.
- Decodes container meta.inventory, which can itself be JSON text. Every resolvable inventory entry becomes an output row using that entry qty and inventory cost/reference/supplier.
- When no entries resolve, emits one row with container amt and stock average cost, blank batch/supplier. Partial resolution does not add a fallback row for missing entries.
- Job and Quote owners are IDs, labeled Job and Quote respectively; user/vehicle/customer names are resolved with ID fallback.
- The Manufacturer/Supplier Part Number column contains only supplier_part_no. Shared stock filters and date controls are ignored.
- No pagination or result limit is implemented. The entire result is exported; a header-only CSV is a valid empty result.
- No stock quantity, audit, edit timestamp, notification or event is changed. Reads across multiple queries are not a transactionally frozen snapshot.
- No direct caller for this exact endpoint was found in the current app JavaScript or
m/wwwintermediary; these are office reporting/source-selection calls, not the app download protocol. - The shared guard rejects non-scalar supplied stock/date filters and validates any supplied stockIDsFilter even on reports that do not use it for selection.
Side effects
- Builds CSV in a checked per-request php://temp stream, then streams it, closes it and exits. No shared tenant filename is written; concurrent requests generate independent files.
See it in Fieldmotion
CRM1
No direct caller for this exact endpoint was found in CRM1. Its Stock page has separate warehouse, user, vehicle, customer and cost export actions.
CRM2
Open Stocks, choose Export, select the matching report and submit. Filter Network for Stock_exportAllocates (the posted form uses php/api.php with extra=/Stock_exportAllocates). CRM2 supplies yes=really and a comma-separated stockIDsFilter for the selected export scope.
Related endpoints
Stock_exportSummaryprovides the CSV destination-type summary.Stock_getCostsprovides single-item costing defaults.Stock_getNamesresolves catalog labels.