Contracts
Import contracts from CSV
/a/Contracts_import
Create or overwrite contracts row by row from CRM’s mapped CSV-import payload and record an import-history batch.
When to use this endpoint
Use Contracts_import only through Fieldmotion’s Contracts import widget after the user maps CSV columns.
For controlled integrations, create/update contracts individually so validation failures can be handled per record.
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 |
|---|---|---|---|
map | JSON array string | Yes | Column mappings; each item’s to determines the parameter copied from the same row index. The handler does not validate the decoded shape before iterating. |
rows | JSON array string | Yes | CSV rows as arrays. Blank/nonpositive mapped ID creates; a positive ID calls the legacy edit path. There is no documented row limit or transaction. |
filename | String | No | Nonblank source name added to import-log metadata when the current tenant schema supports it. |
Example request
$result = FM_api('Contracts_import', [
'map' => json_encode([
['to' => 'id'],
['to' => 'name'],
['to' => 'notes'],
['to' => 'budget'],
['to' => 'type'],
]),
'rows' => json_encode([
['', 'North Region Service Contract', 'Imported', '25000', 'Planned service'],
]),
'filename' => 'contracts.csv',
]);
Example response
{
"ok": 1,
"errors": [],
"ids": [720]
}
ids follows input row order and can contain 0 for a failed create. The current implementation never appends to errors.
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: map"} | The map key is omitted. |
{"error":"missing or invalid parameter: rows"} | The rows key is omitted. |
Server error/runtime warning | Either JSON value is malformed/non-array, a row is shorter than its map, or a map item lacks the expected keys. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- Recognized map targets are
id,active,address,budget,cost,date_completed,date_started,expiry,customer_id,name,notes,price_net,profit,tax, andtype. - Of those, legacy create/edit actually persist name, address, budget, lifecycle dates, expiry, notes, and resolved type. Active, customer, cost, net, profit, and tax are copied but ignored by the called contract handlers. CRM2’s offered Number and Manager columns are not recognized by this switch.
- Type names are matched exactly against contract types. A missing type name is created through
ContractTypes_newbefore the contract row continues. - New rows call
Contract_newand thenContract_edit; existing positive IDs call onlyContract_edit. The edit route’s replacement and metadata-loss behavior therefore applies.
Side effects
- Tags successful creates with
created_by_import_idand all successful writes withedited_by_import_id, preserving prior metadata where possible. - Creates an
imports_logentry with type5, created/edited counts, user, and a time/random import ID. Later import-history deletion can use those metadata tags to soft-delete created rows. - The row writes, type creation, metadata tags, and import log are not transactional.
See it in Fieldmotion
CRM1
On Contracts, choose Import, upload a CSV, map fields, and filter Network requests for Contracts_import.
CRM2
The CRM2 Contracts module uses the same import endpoint from its Import action and sends the mapped rows produced by widgetImport.
Related endpoints
Contract_newhandles each create row.Contract_edithandles each legacy overwrite.Contracts_listByNameshelps import widgets resolve contract names in other object imports.