## Save the CRM module configuration (tenant:crm:admin or tenant:settings:write)

`PUT /api/crm/v1/config`

Module: CRM · operationId: `saveCrmConfig` · Tag: Configuration · Auth: access token (`Authorization: Bearer <accessToken>`)

Replaces the CRM settings: fields left out get their default. The NFON phone book
settings stay as they are; invalid custom field definitions are refused with `400`
(`invalid_custom_fields`); a `nfon` object in the body is ignored (use `saveNfonConfig`).

### Request body

`application/json` (required)

- `active` (boolean): Marks the CRM module as set up for the tenant (`getCrmConfigStatus`); the API does not refuse requests of an inactive module.
- `customFields` (object): The tenant's own fields of leads and opportunities.
  - `lead` (array of CustomFieldDef): Fields of leads.
    - `key` (string, required): Lower-case letters, digits, `-` or `_`.
    - `kind` (string, required): Field type. (one of `text`, `longtext`, `number`, `date`, `datetime`, `bool`, `select`, `multiselect`, `user`, `url`)
    - `label` (string, required): Label shown in forms.
    - `options` (array of object): Choices of `select` and `multiselect` fields (required there).
      - `label` (string, required): Label shown in forms.
      - `value` (string, required): Stored value.
      - `color` (string): Display colour.
    - `required` (boolean): A value is required on write. (default `false`)
  - `opportunity` (array of CustomFieldDef): Fields of opportunities.
    - `key` (string, required): Lower-case letters, digits, `-` or `_`.
    - `kind` (string, required): Field type. (one of `text`, `longtext`, `number`, `date`, `datetime`, `bool`, `select`, `multiselect`, `user`, `url`)
    - `label` (string, required): Label shown in forms.
    - `options` (array of object): Choices of `select` and `multiselect` fields (required there).
      - `label` (string, required): Label shown in forms.
      - `value` (string, required): Stored value.
      - `color` (string): Display colour.
    - `required` (boolean): A value is required on write. (default `false`)
- `defaultLeadSource` (string): Source of new leads created without one. (default `"MANUAL"`; max length 64)
- `leadAutoScoring` (boolean): New leads without a `score` get the data quality score; `false`: 0. (default `true`)
- `leadRetentionMonths` (integer): Months after which a daily job anonymises `LOST` leads and `NEW` / `CONTACTED` leads without change or activity (see Model); 0 is off. (default `0`; max 120)
- `vatCheckEnabled` (boolean): `false` makes `validateVatId` answer `409` (`vat_check_disabled`). (default `true`)

Example:

```json
{
  "active": true,
  "customFields": {
    "lead": [
      {
        "key": "branche",
        "kind": "text",
        "label": "Branche"
      }
    ],
    "opportunity": []
  },
  "defaultLeadSource": "MANUAL",
  "leadAutoScoring": true,
  "leadRetentionMonths": 24,
  "vatCheckEnabled": true
}
```

### Responses

- **200** Saved (`application/json`)
- **400** Invalid input (`invalid`): `field` names the first invalid field, `details.fields` every one (JSON paths for
bodies, parameter names for the query). Some refusals have their own code (`invalid_sort`,
`invalid_stages`, `invalid_custom_fields`, `convert_target_required`, `invalid_csv`, …).
 (`application/json`)
- **401** Missing, invalid or expired token (no body).
- **403** The token lacks the permission (`insufficient permissions`) or has no active tenant.
 (`application/json`)
- **500** Unexpected error; details are only logged. (`application/json`)

Fields of the 200 answer:

- `status` (string): (one of `saved`)

Example 200 answer:

```json
{
  "status": "saved"
}
```

### Example request

```bash
curl -X PUT 'https://api.mbcom.cloud/api/crm/v1/config' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"active":true,"customFields":{"lead":[{"key":"branche","kind":"text","label":"Branche"}],"opportunity":[]},"defaultLeadSource":"MANUAL","leadAutoScoring":true,"leadRetentionMonths":24,"vatCheckEnabled":true}'
```
