## Update an opportunity (tenant:crm:write)

`PUT /api/crm/v1/opportunities/{id}`

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

Partial update; only the fields sent change. A changed `leadId` or `addressId` is checked
like on create (`422`, `502`). Changing `stage` follows the rules of the stage (`400`
`unknown_stage`, `422` `lost_reason_required`); `closedAt` is set when a won or lost stage is
entered and cleared when it is left, a stage change without `probability` takes the stage's
probability and writes a `SYSTEM` activity. Emits `crm.opportunity.updated`, `crm.opportunity.won`
or `crm.opportunity.lost` when it enters such a stage.

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | string (uuid) | yes | Record ID (UUID). |

### Request body

`application/json` (required)

- `addressId` (string (uuid)): A masterdata address of the tenant (`422` otherwise).
- `customFields` (object): Values by field key; validated against the tenant's definitions.
- `expectedCloseDate` (string (date-time)): Expected close date.
- `leadId` (string (uuid)): A lead of the tenant (`422` otherwise).
- `lostReason` (string): Required when the stage is a lost stage. (max length 2000)
- `notes` (string): Notes. (max length 10000)
- `ownerEmail` (string): An empty string removes the owner. (max length 255)
- `probability` (integer): Win probability in percent. (max 100)
- `stage` (OpportunityStage): Key of a stage of the tenant (`listStages`). The defaults are `PROSPECTING`, `QUALIFICATION`, `PROPOSAL`, `NEGOTIATION`, `CLOSED_WON` and `CLOSED_LOST`. (max length 64)
- `title` (string): Title of the opportunity. (max length 255)
- `value` (number (double)): Expected value. (max 9999999999)

Example:

```json
{
  "probability": 100,
  "stage": "CLOSED_WON"
}
```

### Responses

- **200** The updated opportunity (`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`)
- **404** The record does not exist in the token's tenant. (`application/json`)
- **422** A referenced record (lead, masterdata address) does not exist in the tenant, or the change is not
possible as sent; `code` says why (`lost_reason_required`).
 (`application/json`)
- **500** Unexpected error; details are only logged. (`application/json`)
- **502** An upstream service (masterdata, VAT check) failed, is switched off or is not configured. (`application/json`)

Fields of the 200 answer:

- `createdAt` (string (date-time), required): Creation time.
- `customerNo` (string, required): Customer number of the tenant.
- `id` (string (uuid), required): Id of the opportunity.
- `probability` (integer, required): Win probability in percent. (max 100)
- `stage` (OpportunityStage, required): Key of a stage of the tenant (`listStages`). The defaults are `PROSPECTING`, `QUALIFICATION`, `PROPOSAL`, `NEGOTIATION`, `CLOSED_WON` and `CLOSED_LOST`. (max length 64)
- `tenantName` (string, required): Tenant name.
- `title` (string, required): Title of the opportunity.
- `updatedAt` (string (date-time), required): Time of the last change.
- `value` (number (double), required): Expected value.
- `addressId` (string (uuid)): Masterdata address; omitted when not set.
- `closedAt` (string (date-time), read-only): Set by the server when the opportunity enters a won or lost stage, cleared when it leaves.
- `customFields` (object): Values of the tenant's opportunity fields by field key.
- `expectedCloseDate` (string (date-time)): Omitted when not set.
- `leadId` (string (uuid)): Omitted when not set.
- `lostReason` (string): Required in a lost stage, cleared when the opportunity leaves it; omitted when not set.
- `notes` (string): Omitted when not set.
- `ownerEmail` (string): Employee responsible for the opportunity; omitted when not set.

Example 200 answer:

```json
{
  "addressId": "0e2a4c6e-8a1b-4d3f-9b5d-7f9b1d3f5a7b",
  "createdAt": "2026-11-04T09:15:00Z",
  "customFields": {
    "budget-freigegeben": true,
    "entscheider": "Eva Gaßner"
  },
  "customerNo": "99999",
  "expectedCloseDate": "2026-12-15T00:00:00Z",
  "id": "7d9f1b3d-5e7a-4c9b-8f1d-5c7e9a1b3d5f",
  "leadId": "5b7d9f1a-3c5e-4a7b-9d1f-3a5c7e9b1d3f",
  "notes": "Acht Access Points, Controller und Ausleuchtung; Montage in der Betriebspause.",
  "ownerEmail": "lena.vogel@muster-it.example",
  "probability": 50,
  "stage": "PROPOSAL",
  "tenantName": "DEMO",
  "title": "WLAN Sudhaus und Lager",
  "updatedAt": "2026-11-12T16:40:00Z",
  "value": 18400
}
```

### Example request

```bash
curl -X PUT 'https://api.mbcom.cloud/api/crm/v1/opportunities/3f2b8c1e-6d4a-4f7b-9a2e-1c5d7e9f0a12' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"probability":100,"stage":"CLOSED_WON"}'
```
