Marketing
Query the CRM1 Marketing Expense table
/a/MarketingExpenses_getDT
Return CRM1’s positional Marketing Expense table with relative date/source filters, paging, and amount formatting.
When to use this endpoint
Use MarketingExpenses_getDT only to reproduce CRM1’s Settings table. Its row positions and relative-date behavior are coupled to that screen.
Authentication and permissions
The request must authenticate with signed API-key fields or a logged-in CRM session. The handler requires login but performs no additional Marketing-page, create, edit, delete, or role-permission check.
All reads and writes use the authenticated tenant’s tables. CRM1 and CRM2 hide some controls through client-side permissions; these routes do not repeat those UI checks.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
draw | Integer string | Yes | DataTables counter returned as an integer. |
start, length | Integer strings | Effectively yes | Zero-based offset and page size. Both are read without validation. |
order[0][column] | Integer string | Effectively yes | 0 sorts ID, 1 source ID, and 3 expense date. Other values, including the amount column, fall back to source ID. |
order[0][dir] | String | Effectively yes | Exact desc selects descending; other values select ascending. |
dateFrom | Integer day offset | Conditional | With dateTo, lower bound is expense date greater than or equal to the database server’s current date plus this many days. |
dateTo | Integer day offset | Conditional | With dateFrom, upper bound is expense date strictly earlier than database NOW() plus this many days. CRM1 defaults to 0. |
source | Integer string | No | A positive value filters exact source ID. Zero/all omits the filter. |
search[value] | String | Do not use | The handler exposes a legacy search branch, but it references a nonexistent name column on the expense table. CRM1 disables searching. |
Example request
$table = FM_api('MarketingExpenses_getDT', [
'draw' => '3',
'start' => '0',
'length' => '25',
'order' => [['column' => '3', 'dir' => 'desc']],
'dateFrom' => '-30',
'dateTo' => '0',
'source' => '30124',
]);
Example response
{
"data": [["7124","30124",425.5,"01-10-2026",""]],
"draw": 3,
"recordsTotal": "40",
"recordsFiltered": "1"
}
Each row is expense ID, source ID, numeric expense, fixed DD-MM-YYYY expense date, and an empty action placeholder. Source names loaded by the handler are not included.
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: draw"} | draw is absent. |
Database failure/empty malformed response | Nonblank search or invalid raw date-offset/pagination values make the constructed query fail. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
recordsTotalcounts all expenses;recordsFilteredapplies the relative date and source filters before pagination.- The relative-date expressions use database-server
NOW(), not the tenant timezone setting, and the upper boundary retains the current time-of-day. - There is no active/deleted state and no stable secondary ordering.
See it in Fieldmotion
CRM1
Open Settings → Marketing → Expense in CRM1 and filter browser developer tools for the exact function name. Changing the From/To dates, source selector, sort, or page calls this route. Date offsets are stored in browser local storage.
CRM2
CRM2 uses MarketingExpenses_getDataTable.
Related endpoints
MarketingExpenses_getDataTableis CRM2’s mapped alternative.MarketingSources_listresolves source IDs displayed in this response.