# 推播端點

> 送出推播的所有網址寫法和方法、批次推播、頻道推播，以及回應的每個欄位。

這一頁列出推播端點和它們的回應。參數本身（標題、等級、鈴聲、按鈕、排程等）見[參數](/zh-Hant/docs/push/parameters)；想從頭了解怎麼送，見[送出推播](/zh-Hant/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-Hant/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-Hant/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-Hant/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-Hant/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-Hant/docs/push/update-and-recall)。
