> ## Documentation Index
> Fetch the complete documentation index at: https://docs.molesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 合并事件

> 把其他进行中的事件并入一个主事件。

```http theme={null}
POST /api/v1/alerts/incidents/{id}/merge
```

把 `source_ids` 里的事件并入事件 `{id}`。并入的事件在 `merged_into` 里记下主事件，此后不再发通知、不再升级，也不再出现在[列出事件](https://docs.molesignal.com/zh-Hans/api/alerting/list-incidents.md)和洞察里；它仍算进行中，所以它的规则或来源不会为它再开新事件。主事件解决时，并入的事件一并解决；并入的事件先自行恢复时，主事件的[时间线](https://docs.molesignal.com/zh-Hans/api/alerting/incident-timeline.md)记一笔。先前并入被并入事件的事件，一起改挂到主事件下。合并不能撤销。

主事件和每个并入的事件都要是进行中、且没有并入别处的。`source_ids` 里主事件自己的 ID 和重复的 ID 会被忽略。该调用需要对主事件的 `alerts.incidents.escalate`。

**请求体**

| 字段 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `source_ids` | array | 是 | 要并入的 1 到 50 个事件 ID。 |

```bash cURL theme={null}
curl -X POST http://localhost:5080/api/v1/alerts/incidents/$INCIDENT_ID/merge \
  -H "authorization: Bearer $MS_TOKEN" \
  -H "content-type: application/json" \
  -d '{"source_ids": ["<incident-id>", "<another-incident-id>"]}'
```

响应是主事件，各字段说明见[列出事件](https://docs.molesignal.com/zh-Hans/api/alerting/list-incidents.md)。

```json 200 theme={null}
{
  "id": "3KEDNEyqouYJeBDTLTMTBui7XHW",
  "org_id": "<organization-id>",
  "rule_id": "3KEDBLvTYO6DnWi8H9S9MNLpPT7",
  "escalation_policy_id": "<policy-id>",
  "status": "open",
  "severity": "critical",
  "summary": "High error rate · checkout",
  "fingerprint": "2b7f5329675de7077c74ffa2646a36cd3adf16f80f523270332894d1ff630632",
  "current_step": 0,
  "current_loop": 0,
  "current_step_started_at": 1790000300000000,
  "assignees": [
    "<user-id>"
  ],
  "labels": {
    "service": "checkout"
  },
  "annotations": {},
  "trace_ids": [],
  "host_ids": [],
  "affected_services": [
    "checkout"
  ],
  "created_at": 1790000000000000,
  "acknowledged_at": null,
  "acknowledged_by": null,
  "resolved_at": null,
  "resolved_by": null,
  "team_id": "<team-id>",
  "routing": {
    "reason": "default"
  },
  "snoozed_until": null,
  "snoozed_by": null,
  "assignees_pinned": false,
  "severity_set_by": null,
  "merged_into": null,
  "dispatch_round": 0,
  "dispatch_reason": "step",
  "revision": 4
}
```

**错误**

| 状态码 | 原因 |
| - | - |
| `400` | `source_ids` 里没有别的事件，或超过 50 个。 |
| `403` | Token 缺少 `alerts.incidents.escalate`，或无权访问这个事件。 |
| `404` | 主事件或 `source_ids` 里的某个事件不存在。 |
| `409` | 主事件或 `source_ids` 里的某个事件已恢复或已并入别处，或者更新时事件一直在变；重试即可。 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.