Contracts
Create a contract through the field map
/a/Contract_createData
Create a contract through CRM2’s mapped layout engine and publish its create notifications.
When to use this endpoint
Use Contract_createData from the CRM2 configurable Contracts list or Kanban workflow, where request keys follow the contract field map.
Use Contract_new when you need the older create contract, initial job links, or explicit name validation.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
name | String | No | Contract name, limited to 64 characters when supplied. Unlike Contract_new, this wrapper does not require it. |
notes | String | No | Stored notes; defaults to an empty string. Mention syntax can create notices after insertion. |
expiryDate | Date string | No | Mapped YYYY-MM-DD expiry. Blank, numeric NaN-like input, and exact NaN-NaN-NaN become null; other invalid dates are rejected by the shared mapper. |
cDate | Date-time string | No | Creation date-time; defaults to the current server time. |
active | Integer string | No | Stored status value. Omission leaves the table default, normally 1. |
customers | String | No | Raw cached customer/asset representation. This endpoint does not derive or validate it. |
customValues | JSON object or array | No | Complete mapped custom JSON value stored in custom; defaults to {}. |
budget | Number | No | Mapped floating-point contract budget. |
number / address / manager | Strings | No | Reference number, address, and manager fields. |
typeID / createdBy | Integer strings | No | Contract-type and creator IDs. createdBy is always replaced with the authenticated user ID. |
dateStarted / dateCompleted | Date / date-time | No | Mapped lifecycle dates. |
meta / metaHoursBudget / metaNotInvoiceable / metaStage | JSON or mapped scalar | No | The supplied top-level meta is replaced with defaults: spend and hours-spent status ok and not_invoiceable="0". Nested mapped values may then modify those properties. |
Example request
$created = FM_api('Contract_createData', [
'name' => 'North Region Service Contract',
'typeID' => '8',
'budget' => '25000',
'expiryDate' => '2027-09-30',
]);
Example response
{
"ok": 1,
"id": 720
}
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":"name has a maximum length of 64"} | The shared mapped conversion rejects an overlong name. Exact wording can vary with mapper validation. |
{"error":"invalid date parameter: expiryDate"} | A nonblank mapped expiry is not a valid YYYY-MM-DD value. |
{"error":"missing or invalid parameters."} | No mapped value remains to insert; wrapper 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. The contract field map controls coercion, date validation, JSON storage, and the 64-character name limit.
- The endpoint does not link jobs, derive customers/assets, require a name, or provide pagination.
- The fixed metadata defaults differ from
Contract_new, which begins withcustomersDirty=1.
Side effects
- Inserts the tenant contract, writes generic field-level activity logs, and sets
last_edited. - Sends mention notices found in mapped notes and publishes create/time notifications to the notifications service. These effects are not transactional with the insert.
See it in Fieldmotion
CRM1
No production CRM1 caller was found. CRM1 creates contracts through Contract_new.
CRM2
Open Contracts in CRM2, use the configurable create action or create a Kanban card, and filter Network requests for Contract_createData.
Related endpoints
Contract_newis the legacy create route with job-link support.Contract_updateDataupdates fields from the same map.Contract_setExpiryDatestores an expiry and synchronizes all expiry work.