# Write an incident's postmortem (PUT)

`PUT https://evohub.io/api/v1/incidents/{id}/postmortem`

Part of the [On-Call API](https://docs-dev.evohub.io/oncall.md) reference · operationId `replacePostmortem`.

Creates the incident's postmortem, or replaces every field of the existing
one: a field left out is stored empty. `status` defaults to `draft` on
creation. Setting it to `published` records `published_at` the first time and,
when the incident is on a status page, posts the postmortem there. The caller
becomes the author. POST and PUT do the same thing.

**Permission (API-key scope):** `oncall:postmortem:write`.

## Authorization

Any one of:

- `bearerAuth` (oncall:postmortem:write)
- `apiKeyHeader` (oncall:postmortem:write)

Where:

- `bearerAuth`: HTTP Bearer — An EvoHub API key (`evohub_…`) as a bearer token.
- `apiKeyHeader`: API key in the header `X-API-Key` — An EvoHub API key (`evohub_…`).

## Path parameters

- `id` (string, required, example `2e7f9a1b-3c4d-4e5f-8a9b-0c1d2e3f4a5b`): The incident's id.

## Request body (required)

Content type: `application/json`

Type: `PostmortemWrite`

Every field is written as sent; one left out is stored empty.

- `status` (PostmortemStatus, one of `draft`, `in_review`, `published`)
- `summary` (string)
- `root_cause` (string)
- `contributing_factors` (string)
- `timeline` (string)
- `action_items` (string)
- `lessons_learned` (string)

## Responses

### 200 — The postmortem.

Content type: `application/json`

Type: `object`

- `data` (Postmortem, required)
  - `id` (string)
  - `org_id` (string)
  - `incident_id` (string)
  - `author_id` (string)
  - `status` (PostmortemStatus, one of `draft`, `in_review`, `published`)
  - `summary` (string)
  - `root_cause` (string)
  - `contributing_factors` (string)
  - `timeline` (string)
  - `action_items` (string)
  - `lessons_learned` (string)
  - `published_at` (string (date-time))
  - `created_at` (string (date-time))
  - `updated_at` (string (date-time))
- `success` (boolean, required, value `true`)

### 400 — The body is not valid JSON (`INVALID_BODY`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 401 — No API key was sent, or it is unknown, revoked or expired (`UNAUTHORIZED`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 403 — The key lacks the scope this endpoint needs (`FORBIDDEN`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 404 — No incident with this id in your organization (`NOT_FOUND`).

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 429 — Too many requests (`RATE_LIMITED`). Wait `Retry-After` seconds.

Headers:

- `Retry-After` (integer): Seconds to wait.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

### 500 — Something went wrong on EvoHub's side (`INTERNAL_ERROR`). Retry later.

Content type: `application/json`

Type: `Error`

- `error` (object, required)
  - `code` (string, required): Machine-readable code. Branch on this.
  - `message` (string, required): Human-readable explanation.

## Example request

```bash
curl -X PUT 'https://evohub.io/api/v1/incidents/2e7f9a1b-3c4d-4e5f-8a9b-0c1d2e3f4a5b/postmortem' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <TOKEN>' \
  -d '{
  "status": "draft",
  "summary": "Payments timed out for 42 minutes.",
  "timeline": "08:01 first alert; 08:43 rollback complete.",
  "root_cause": "A connection pool limit was lowered in the v2.15.0 release.",
  "action_items": "Alert on pool saturation; load test pool changes.",
  "lessons_learned": "Configuration changes need the same review as code.",
  "contributing_factors": "No alert on pool saturation."
}'
```
