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

ParameterTypeRequiredDescription
drawInteger stringYesDataTables counter returned as an integer.
start, lengthInteger stringsEffectively yesZero-based offset and page size. Both are read without validation.
order[0][column]Integer stringEffectively yes0 sorts ID, 1 source ID, and 3 expense date. Other values, including the amount column, fall back to source ID.
order[0][dir]StringEffectively yesExact desc selects descending; other values select ascending.
dateFromInteger day offsetConditionalWith dateTo, lower bound is expense date greater than or equal to the database server’s current date plus this many days.
dateToInteger day offsetConditionalWith dateFrom, upper bound is expense date strictly earlier than database NOW() plus this many days. CRM1 defaults to 0.
sourceInteger stringNoA positive value filters exact source ID. Zero/all omits the filter.
search[value]StringDo not useThe 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

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: draw"}draw is absent.
Database failure/empty malformed responseNonblank 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

  • recordsTotal counts all expenses; recordsFiltered applies 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