Marketing
Create a legacy marketing expense
/a/MarketingExpense_new
Create one marketing-spend row from CRM1’s compact Expense dialog.
When to use this endpoint
Use MarketingExpense_new for CRM1 compatibility. Prefer MarketingExpense_createData for validated mapped dates and change history.
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 |
|---|---|---|---|
source | Numeric-compatible | Yes | Source ID converted with floatval(). The endpoint does not verify that the source exists. |
expense | Numeric-compatible | Yes | Amount converted with floatval(). Blank/nonnumeric becomes 0 if the key is present. |
expenseDate | String | Yes | Date text inserted into the database date column. Presence is checked, but format is not validated at application level. CRM1 sends YYYY-MM-DD. |
Example request
$expense = FM_api('MarketingExpense_new', [
'source' => '30124',
'expense' => '425.50',
'expenseDate' => '2026-10-01',
]);
Example response
{"ok":1,"id":7124}
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: source"} | source is absent. |
{"error":"missing or invalid parameter: expense"} | expense is absent. |
{"error":"missing or invalid parameter: expenseDate"} | expenseDate is absent. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Creation and last-edit times are set to the current server Unix timestamp.
- No source relationship, amount range, currency, or duplicate check is performed.
Side effects
- Inserts the expense row and invalidates the marketing-expense cache. It does not write Core field history.
See it in Fieldmotion
CRM1
Open Settings → Marketing → Expense in CRM1 and filter browser developer tools for the exact function name. Choose Create, select a source, enter an amount/date, and submit.
CRM2
CRM2 uses MarketingExpense_createData through its shared create form.
Related endpoints
MarketingExpense_createDatavalidates the date and records changes.MarketingExpense_getRequestedDetailsretrieves the inserted ID.