When to use this endpoint

Use MarketingExpense_export after collecting filtered expense IDs from MarketingExpenses_getDataTable. It streams a file and exits rather than returning JSON.

Authentication and permissions

The request must authenticate with signed API credentials or a logged-in CRM session and satisfy exportTableData on pageMarketingExpense. Client administrators pass automatically; legacy roles without an explicit role ID retain the compatibility allow behavior.

The exported IDs are selected only from the authenticated tenant.

Parameters

ParameterTypeRequiredDescription
expenseIDsComma-separated integersYesExpense IDs to export. Each token is integer-converted. Blank is accepted as ID 0 and produces a header-only CSV.

Example request

// Capture this call as raw CSV rather than decoding JSON.
$csv = FM_api('MarketingExpense_export', [
	'expenseIDs' => '7124,7125',
]);

Example response

ID,"Date Created","Lead Source",Expense,"Expense Date"
7124,01/10/2026,30124,425.5,01/10/2026

The response uses Content-Type: text/csv and attachment filename marketingExpense.csv. Despite the Lead Source heading, that column contains the numeric source ID, not its name.

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: expenseIDs"}The key is absent. This check occurs before the login guard.
{"error":"permission denied"}The authenticated role lacks the Marketing Expense export permission.
{"error":"filesize too great for export - over 10000 rows of data found. Please narrow the date range and try again"}More than 10,000 rows match the supplied IDs.

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

Behaviour and edge cases

  • There is no row ordering in the export query and no built-in batching.
  • Date columns use the tenant date-format setting after consecutive duplicate format letters are collapsed. Creation time is converted to tenant-local time first.
  • The endpoint fetches the full selected set before enforcing the 10,000-row maximum.
  • Unknown and duplicate IDs are simply absent/collapsed by SQL.

Side effects

  • Writes a temporary tenant-scoped marketingExpense.csv, streams it, and terminates the request.

See it in Fieldmotion

CRM1

No CRM1 production caller was found; the legacy Marketing Expense page has no export control.

CRM2

Open Marketing → Marketing Expenses in CRM2 and filter browser developer tools for the exact function name. Choose Export. CRM2 first requests up to 100,000 filtered IDs, then submits them to this endpoint. The export button is shown only when the same permission passes client-side.

Related endpoints