Opportunities
Query the mapped Opportunities table
/a/Opportunities_getDataTable
Query CRM2’s mapped Opportunities table with named fields, generic filters, callback ranges, and restricted-user customer scope.
When to use this endpoint
Use Opportunities_getDataTable for CRM2 table/Kanban data or unpaged export-ID discovery that must match CRM2 filters.
Authentication and permissions
This handler does not call Core_requireLogin or perform a page-permission check. The normal dispatcher and tenant-routing requirements still apply, but callers must not treat this route’s PHP function as an authorization boundary.
If a user session is present and is not a client administrator, the handler can apply department/account-manager customer restrictions described below.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
fields | Native array | Yes | Requested opportunity map keys; unknown keys are ignored and id is always returned. Composite user/customer/quoteID fields return objects with id. |
isTable / draw / start / length / limit | Integer-compatible | No | Table mode defaults on with offset 0, length 10, and draw 0. Exact isTable=0 removes count/paging; positive limit then caps rows. |
orderBy / orderDesc / order | Shared mapped ordering | No | Explicit named ordering or DataTables fallback. With no orderBy, this wrapper defaults to createDate ascending. |
searchValue / searchField | String / mapped name(s) | No | Case-insensitive substring search over one/many mapped fields or All, including related customer/user/status/source names. |
referenceDate / dateFrom / dateTo / offsets / time range | Shared mapped date controls | No | Relative tenant-calendar date/time filtering when referenceDate is a mapped date field. |
Mapped filters / advanceSearch / groupBy | Shared scalar/native-array controls | No | Generic mapped filters, advanced conditions, and grouping. |
customer | Native picker object(s) | No | Customer filter values with id/type; opportunity customers use type 0. |
childJobAndAsset | Native array | No | If nonzero/present with customer, containing value 0 expands each type-0 customer filter to include its direct child customers. Despite the legacy name, no asset rows are involved. |
metaCallbackStatus | Native integer array | No | OR-combined callback buckets: -2 before today, -1 yesterday, 0 today, 1 tomorrow, 2 after today. Dates use the PHP server calendar. |
Example request
$table = FM_api('Opportunities_getDataTable', [
'fields' => ['id', 'customer', 'user', 'value', 'status', 'metaCallback'],
'start' => 0,
'length' => 25,
'draw' => 4,
'orderBy' => 'createDate',
'orderDesc' => 'desc',
]);
Example response
{
"data": [
{"id":"481","customer":{"id":"1042"},"user":{"id":"18"},"value":"2500","status":"1","metaCallback":"2026-10-01 09:00:00"}
],
"draw": 4,
"recordsTotal": "37",
"recordsFiltered": "12"
}
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"missing or invalid parameter: fields"} | fields is absent. |
{"error":"error in database query"} | Generated selection/filter/order SQL fails. |
Runtime type error | Fields, composite filters, child expansion, callback buckets, grouping, or advanced controls have unsupported shapes. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Soft-deleted opportunities are excluded. If an enabled row restriction resolves no customers, the result is forced empty.
- Callback buckets operate on
meta.callbackstrings. An array containing only unsupported bucket values builds an empty SQL group and can fail. - If no explicit
orderByis sent but acreateDatefilter parameter exists, its value is mistakenly tried as the order-field name before the shared fallback chooses a requested mapped field. - The handler itself does not check the tenant Opportunities feature switch. CRM2 hides the module unless that feature is enabled and uses client-side view/edit/delete/export permissions.
See it in Fieldmotion
CRM1
CRM1 uses the positional Opportunities_getDT route.
CRM2
The Opportunities table and Kanban view use this route. The export flow also calls it with fields=["id"] and isTable=0 to collect filtered IDs.
Related endpoints
Opportunities_getDTis the legacy table endpoint.Opportunities_getExportDataresolves CSV fields for selected IDs.