Marketing
Create a mapped marketing expense
/a/MarketingExpense_createData
Create a dated marketing-spend row through CRM2’s mapped writer and return its new ID.
When to use this endpoint
Use MarketingExpense_createData for CRM2’s Marketing Expenses create form or whenever strict mapped date validation and field history are required.
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 |
|---|---|---|---|
id | Integer-compatible or native array | No | Ignored for creation; the database assigns the ID. |
source | Integer-compatible | No | Marketing-source ID. It is integer-converted but the endpoint does not verify that the source exists. Omission during creation leaves the database default 0. |
expense | Numeric-compatible | No | Expense amount converted with floatval(). Omission during creation leaves the database default 0. |
expenseDate | Date string | No | Expense date in exact YYYY-MM-DD form. Blank is accepted; other invalid dates are rejected by mapped create/update routes. |
createDate | Unix timestamp or date string | No | Creation time stored as a Unix timestamp. Creation defaults to the current server time. |
lastEdited | Unix timestamp or date string | No | Edit time stored as a Unix timestamp. Creation defaults to now and ordinary updates advance it automatically. |
Example request
$expense = FM_api('MarketingExpense_createData', [
'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":"invalid date parameter: expenseDate"} | A nonblank expense date is not exact YYYY-MM-DD. |
{"error":"missing or invalid parameters."} | No mapped/defaulted value can be constructed. With the current timestamp defaults, an otherwise empty request normally still creates a row. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- The source ID is not checked against
marketing_sources. Orphaned expense rows can be created. - Expense is float-converted. The schema stores a floating-point value rather than a fixed decimal.
- Creation and edit timestamps default to the current server Unix time.
Side effects
- Inserts the tenant row, invalidates the marketing-expense cache, and records mapped field additions in Core history.
See it in Fieldmotion
CRM1
CRM1’s Expense Create dialog calls MarketingExpense_new.
CRM2
Open Marketing → Marketing Expenses in CRM2 and filter browser developer tools for the exact function name. Choose Create; the shared display widget derives this mapped route.
Related endpoints
MarketingExpense_getRequestedDetailsreads the new row.MarketingExpense_newis CRM1’s less-validated creator.