# 推送端点

> 发送推送的所有网址写法和方法、批量推送、频道推送，以及响应的每个字段。

这一页列出推送端点和它们的响应。参数本身（标题、等级、铃声、按钮、定时等）见[参数](/zh-Hans/docs/push/parameters)；想从头了解怎么发送，见[发送推送](/zh-Hans/docs/push)。

## 端点 [#端点]

| 方法 | 路径 | 说明 |
|---|---|---|
| `GET` `POST` | `/{device_key}` | 参数全部放在 query 或正文 |
| `GET` `POST` | `/{device_key}/{body}` | |
| `GET` `POST` | `/{device_key}/{title}/{body}` | |
| `GET` `POST` | `/{device_key}/{title}/{subtitle}/{body}` | |
| `POST` | `/push` | 正文带 `device_key` 或 `device_keys` |
| `GET` `POST` | `/c/{push_key}`，以及同样三种路径写法 | 推到[团队频道](/zh-Hans/docs/teams/channels) |

设备 key 是 22 个英文字母和数字。路径里的每一段都要做网址编码。

同一个参数出现在好几个地方时，路径优先于 query string，query string 优先于正文。

```bash
# 路径
curl "https://opu.sh/YOUR_KEY/备份完成/花了12分钟"

# Query
curl "https://opu.sh/YOUR_KEY?title=备份完成&group=backups&level=passive"

# JSON
curl -X POST https://opu.sh/push \
  -H "Content-Type: application/json" \
  -d '{"device_key":"YOUR_KEY","title":"备份完成","body":"12 分钟备份了 42 GB"}'
```

有路径前缀的企业服务器，在主机根目录也收 `POST /push`，因为 Apprise 不能加前缀。

## 批量推送 [#批量推送]

在发送到 `/push` 的 JSON 正文里用 `device_keys`，就能把同一条推送发送到好几台设备。可以是数组，也可以是逗号分隔的字符串。其他内容类型不能带 `device_keys`。

```bash
curl -X POST https://opu.sh/push \
  -H "Content-Type: application/json" \
  -d '{"device_keys":["KEY_ONE","KEY_TWO"],"title":"v2.0 发布了"}'
```

每次请求能带的 key 数有上限，超过时整个请求回 `400`，`message` 会写出上限。

批量一律回 `200`，每台设备的结果各自放在 `data` 里。每一条也可能带 `schedule`、`call`、`sms`、`phone`、`escalation`，内容和下面说明的相同：

```json
{
  "code": 200,
  "message": "success",
  "timestamp": 1793546000,
  "data": [
    { "code": 200, "device_key": "KEY_ONE" },
    { "code": 503, "device_key": "KEY_TWO", "message": "device is unreachable: APNs token expired, open the app to refresh it" }
  ]
}
```

## 响应 [#响应]

推送成功时回 `200`，格式如下：

```json
{ "code": 200, "message": "success", "timestamp": 1793546000 }
```

### message [#message]

| 值 | 意思 |
|---|---|
| `success` | 已交给推送服务 |
| `scheduled` | 已存起来，之后再发送（`at`、`delay` 或 `repeat`） |
| `queued: the Live Activity is starting on the device` | [进度卡片](/zh-Hans/docs/push/live-progress)还没准备好，这次更新先存起来 |

### data [#data]

有东西要回报时才有 `data`。

| 字段 | 什么时候有 | 内容 |
|---|---|---|
| `data.id`、`data.fire_at`、`data.repeat` | 定时推送 | 定时 ID（`sch_…`）、下一次发送的时间、重复规则或 `null` |
| `data.call` | `call=voice` | `{ "placed": true, "call_id": "…" }`；没打的话是 `{ "placed": false, "reason": "…" }`，原因是 `not_enabled`、`group`、`rate_limited` 或 `push_failed` |
| `data.sms` | `sms=1` | `{ "sent": 1 }`；没发送的话是 `{ "sent": 0, "skipped": "…" }`，原因是 `not_configured`、`no_numbers`、`quota`、`rate_limited`、`duplicate` 或 `failed` |
| `data.phone` | `phone=1` | 格式和 `data.sms` 相同 |
| `data.escalation` | `escalate` | 见下方 |

定时推送的 `data` 就是定时本身：

```json
{
  "code": 200,
  "message": "scheduled",
  "timestamp": 1793546000,
  "data": { "id": "sch_…", "fire_at": "2026-11-05T01:50:00Z", "repeat": "weekdays" }
}
```

带 `escalate` 时：

```json
{
  "code": 200,
  "message": "success",
  "timestamp": 1793546000,
  "data": {
    "escalation": {
      "alert_id": "al_…",
      "steps": ["push", "voice", "sms", "phone"],
      "every_minutes": 5,
      "next_at": "2026-11-04T09:35:00Z",
      "status_url": "https://opu.sh/alerts/al_…",
      "callback_secret": "ocs_…"
    }
  }
}
```

只有带了 `callback_url` 才有 `callback_secret`。`status_url` 搭配[告警 API](/zh-Hans/docs/api/alerts) 使用。

### 频道推送 [#频道推送]

推到 `/c/{push_key}` 的推送会发给每个没有把频道静音的成员。`data` 是发送的统计：

```json
{ "channel": "Ops", "devices": 4, "sent": 4, "failed": 0 }
```

带 `oncall=1` 时只发给值班的人，`data` 会多 `on_call`（`account_id`、`name`、`until`），用了 `escalate` 还有 `escalation`，也和个人推送一样有 `call`、`sms`、`phone`。频道没有轮值表的话回 `400`。频道目前不支持定时，带 `at`、`delay`、`repeat` 会回 `400`。见[值班轮替](/zh-Hans/docs/teams/on-call)。

## 错误 [#错误]

错误也是同样的格式，`message` 说明出了什么问题。

| 状态码 | `message` 示例 | 怎么处理 |
|---|---|---|
| `400` | `failed to get device token: device key not found` | 检查 key，可能已经在 App 里换过 |
| `400` | `request bind failed: invalid JSON`、`invalid type for device_keys` | 修正正文 |
| `400` | `batch push count exceeds the maximum limit: …` | 每次少带一些 key |
| `400` | 按钮、定时、`live` 或 `escalate` 的值不对 | 看 `message` 修正参数 |
| `401` | `Unauthorized` | 企业服务器开了 Basic Auth，请带上账号密码 |
| `403` | `account suspended` | 账户已被封禁，请联系客服 |
| `403` | `This device already has … scheduled pushes. Cancel one first.` | 先取消一条定时 |
| `404` | `not found` | key 不是 22 个英文字母和数字，重新拷贝推送网址 |
| `413` | `payload too large: APNs allows 4096 bytes` | 缩短文字，或用 `url` 连到详细内容 |
| `429` | `too many pushes` | 等 `Retry-After` 秒数。方案今天的推送数用完时，可能要等到 UTC 午夜 |
| `500` | `push failed: …` | 稍后再试 |
| `503` | `device is unreachable: APNs token expired, open the app to refresh it` | 在那台设备打开 Opush |
| `503` | `server is busy, try again later` | 等 `Retry-After` 秒数 |

用 `delete=1` 加 `id` 撤回推送时，同一个 `id` 还没发送的定时和正在升级的告警也会一起取消。见[更新和撤回](/zh-Hans/docs/push/update-and-recall)。
