Purchase orders
Download legacy order headers as CSV
/a/PurchaseOrders_export
Stream a fixed-column Purchase Order header CSV directly in the response.
When to use this endpoint
Use the CRM1 Export action when its fixed columns are sufficient. For selected configurable export fields use PurchaseOrders_exportData, which returns JSON rows instead.
Authentication and permissions
Authenticate with signed API-key fields or a logged-in CRM session. Session requests use dispatcher CSRF protection when configured. API keys use their owner’s identity.
Purchase Order View is required on the singular or plural page. Records must be active and inside the configured TeamAccess or legacy Department Based Filter boundary; administrators are exempt from record restrictions. API-key requests use their owner’s identity. Related display names require the corresponding page View and record visibility.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
daysTo | Integer-compatible relative days | No | Optional upper relative day; nonblank integer offsets include the complete selected server day. Blank/omission adds no upper bound. |
search | Text | No | Optional legacy substring search. The exact searched columns differ by export; LIKE wildcards retain meaning. |
Example request
$csv = FM_api('PurchaseOrders_export', [
'daysFrom'=>'-30','daysTo'=>'0','search'=>'PO-318',
]);
Example response
Id,Num,Reference,Supplier,"Date Created","Date Approved","Date Sent","Delivery Date","Linked To","Link Type","Total Net","Total Tax","Carriage Net","Carriage Tax",Status,"Req Order ID","Created By"
1042,318,PO-318,"Example supplier","2026-11-05 09:00:00",,,,,,35.00,7.00,10.00,2.00,Open,0,"Example user"
The example is raw CSV. A no-match request still emits the header row. Database nulls become empty CSV cells.
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"} | The required page permission is missing. Hidden/deleted records are omitted from collections; explicit parent readers reject an inaccessible parent. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Returns text/csv with attachment filename purchase_orders.csv and terminates the request. It is raw CSV, not a JSON string/envelope. Columns are Id, Num, Reference, Supplier, Date Created/Approved/Sent, Delivery Date, Linked To, Link Type, Total Net/Tax, Carriage Net/Tax, Status, Req Order ID, Created By.
- Search lowercases supplier name/reference; numeric search also matches exact row ID rather than po_num. Active visible headers sort by ID, without pagination or cap.
- Raw Total Net/Tax already include carriage; separate carriage columns are informational and must not be added again. Status is a received-state label. Creator/supplier IDs resolve to names; linked Quote/Job values include their displayed number/reference and local ID.
- Related names require their corresponding page View and record visibility. Missing/inaccessible names are blank. Link-type labels include Warehouse (type 7).
- Builds the CSV in a request-local php://temp stream; concurrent exports do not overwrite one another’s file. raw, where supported, changes only the attachment header.
Side effects
- Reads visible order data, writes CSV into a request-local temporary stream, sends download headers and exits. No shared tenant filename, order, stock or financial mutation.
See it in Fieldmotion
CRM1
The CRM1 export buttons are hidden when userdata.permissions bit 256 is set; this endpoint does not enforce that export flag. In CRM1 Purchase Orders, click Export; the page submits a POST form to PurchaseOrders_export with CSRF, relative date controls and the grid search.
CRM2
No direct CRM2 literal caller was found in the searched client source. CRM2 uses its configurable JSON export pipeline.
Related endpoints
PurchaseOrders_getDataTable— Select mapped active header rows.PurchaseOrders_exportData— Read selected configurable header export rows.PurchaseOrder_get— Read one checked raw header.