> ## 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.

# 轮换来源 Token

> 给告警来源换一个新 Token，旧的立即失效。

```http theme={null}
POST /api/v1/alerts/sources/{id}/token
```

给一个[告警来源](https://docs.molesignal.com/zh-Hans/alerting/sources.md)换一个新 Token，需要 `alerts.sources.manage`，请求体为空。旧 Token 立即失效；开了联邦时，其他集群同步到以后失效。还在用旧 Token 的发送方要换上新的。

```bash cURL theme={null}
curl -X POST http://localhost:5080/api/v1/alerts/sources/$SOURCE_ID/token \
  -H "authorization: Bearer $MS_TOKEN"
```

响应是来源加上新的 `token`，`token` 只出现这一次。

```json 200 theme={null}
{
  "id": "3KEJ1mZqf0bY0b8XUgD4tkd2Vwq",
  "name": "Production Prometheus",
  "kind": "alertmanager",
  "enabled": true,
  "escalation_policy_id": "default",
  "severity": "warning",
  "labels": { "team": "payments" },
  "token_prefix": "ms_aB3kZ1xT9pQrU7nM",
  "home_cluster": "",
  "intake_path": "/api/v1/intake/alerts",
  "created_by": "<user-id>",
  "created_at": 1790000000000000,
  "updated_at": 1790000000000000,
  "last_intake_at": null,
  "token": "<token>"
}
```

**错误**

| 状态码 | 原因 |
| - | - |
| `403` | Token 缺少 `alerts.sources.manage`。 |
| `404` | 来源不存在。 |


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