When to use this endpoint

Use Opportunity_createData for CRM2 layout-driven creation. CRM1’s compact dialog uses the narrower Opportunity_new route.

Authentication and permissions

The request must authenticate with signed API-key fields or a logged-in CRM session. The handler performs no additional page or role-permission check.

The lookup and any write use the authenticated tenant; an ID from another tenant cannot be addressed through this call.

Parameters

ParameterTypeRequiredDescription
userNative object/arrayYesAssigned user picker value, normally ["id"=>18]. The nested id becomes user_id; malformed shapes can pass required validation yet store the database default/null.
customerNative object/arrayYesCustomer picker value, normally ["id"=>1042]. Only the nested ID is stored.
sourceInteger-compatibleYesLead-source ID. Presence is required, but zero and nonexistent IDs are not rejected.
value / notes / status / typeInteger / text / integersNoCore values. Status defaults to 1; omitted value/notes use their database defaults.
formID / formValues / subformValuesInteger / JSON-compatible valuesNoOpportunity form and saved field data. Arrays/objects are JSON-encoded; JSON strings are normalized by the shared helper.
widgetFormFieldJSON-compatible valueNoCRM2 alias copied to formValues, taking precedence over a separately supplied formValues.
quoteIDNative object/arrayNoQuote picker value such as ["id"=>9021]. The nested ID becomes quote_id.
isStarred / reasonInteger-compatibleNoStored flags/reason values after integer conversion.
createDate / lastEditedUnix seconds or parseable datetimeNoMapped epoch fields. Both default to the current epoch; supplied nonnumeric values are parsed with strtotime.
createdByInteger-compatibleNoDefaults to the signed-in user. Although layouts mark it read-only, the helper accepts an explicit override.
customValuesJSON-compatible valueNoLayout custom values; defaults to an empty JSON object.
metaCallback / metaCallbackNotes / metaJobDatetime / text / textNoKeys merged into the opportunity meta JSON object.
deletedInteger-compatibleNoMapped soft-delete flag. The generic helper accepts it even though normal creation should omit it.
noRecord / noRecordCustomNative arraysNoAudit-hiding controls. noRecordCustom checks custom keys as intended; noRecord is affected by a legacy stale-variable bug and does not reliably check each mapped field key.

Example request

$created = FM_api('Opportunity_createData', [
	'user' => ['id' => 18],
	'customer' => ['id' => 1042],
	'value' => 2500,
	'notes' => 'Replace reception lighting',
	'source' => 7,
]);

Example response

{
  "ok": 1,
  "id": 481
}

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: user"}user is absent.
{"error":"missing or invalid parameter: customer"}customer is absent.
{"error":"missing or invalid parameter: source"}source is absent.
{"error":"missing or invalid parameters."}No mapped/default field can be prepared for insertion. Defaults normally prevent this response.

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

Behaviour and edge cases

  • Unknown request keys are ignored. Numeric mapped fields are integer-converted; text is stored as supplied; blank JSON/date values become SQL NULL.
  • The mapped type field depends on the tenant having the corresponding opportunity schema upgrade.
  • The public embedded-form workflow also calls this function internally after it validates its configured actor, customer mode, status, source, and optional form.

Side effects

  • Inserts one opportunity, invalidates its cache, and writes per-field creation audit entries—including defaults.
  • Sends mention notices found in notes-compatible fields and queues opportunity create/time notifications.

See it in Fieldmotion

CRM1

CRM1 does not call this route from its Opportunities page.

CRM2

The layout-driven Create Opportunity dialog calls this route. Public embedded forms can call the same function internally under their configured audit user.

Related endpoints