通知の送信
notifyまたはfullスコープの API キー- 通知を送るアプリの App ID
全購読者への送信
Section titled “全購読者への送信”アプリの全アクティブ購読者に通知を送ります。
curl -X POST https://api.todoke.dev/api/v1/notify \ -H "Authorization: Bearer pk_notify_key" \ -H "Content-Type: application/json" \ -d '{ "title": "新着情報", "body": "アップデートがあります", "url": "https://yourapp.com/news", "icon": "https://yourapp.com/icon.png" }'import { PushCF } from "@todoke/sdk";
const client = new PushCF({ apiKey: "pk_notify_key",});
await client.notify({ title: "新着情報", body: "アップデートがあります", url: "https://yourapp.com/news", icon: "https://yourapp.com/icon.png",});await fetch("https://api.todoke.dev/api/v1/notify", { method: "POST", headers: { "Authorization": "Bearer pk_notify_key", "Content-Type": "application/json", }, body: JSON.stringify({ title: "新着情報", body: "アップデートがあります", url: "https://yourapp.com/news", }),});特定ユーザーへの送信
Section titled “特定ユーザーへの送信”endpoint フィールドを指定すると、その購読者のみに送信できます。
curl -X POST https://api.todoke.dev/api/v1/notify \ -H "Authorization: Bearer pk_notify_key" \ -H "Content-Type: application/json" \ -d '{ "title": "あなた宛のメッセージ", "body": "個別通知です", "endpoint": "https://fcm.googleapis.com/fcm/send/..." }'バッチ送信(複数エンドポイントへの一括送信)
Section titled “バッチ送信(複数エンドポイントへの一括送信)”POST /api/v1/notify/batch を使うと、同じ内容の通知を複数の endpoint へ一度にまとめて送信できます。
curl -X POST https://api.todoke.dev/api/v1/notify/batch \ -H "Authorization: Bearer pk_notify_key" \ -H "Content-Type: application/json" \ -d '{ "endpoints": ["https://fcm.googleapis.com/fcm/send/aaa", "https://fcm.googleapis.com/fcm/send/bbb"], "payload": { "title": "新着情報", "body": "アップデートがあります", "url": "https://yourapp.com/news" } }'# → 202 { "queued": 2 }| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
endpoints | string[] | ✅ | 送信先 endpoint の一覧。最大 100 件(超過時は 400 TOO_MANY_ENDPOINTS) |
payload.title | string | ✅ | 通知タイトル |
payload.body | string | ✅ | 通知本文 |
payload.url | string | — | クリック時の遷移先 URL(https:// のみ) |
リクエストパラメータ
Section titled “リクエストパラメータ”| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
title | string | ✅ | 通知タイトル |
body | string | ✅ | 通知本文 |
url | string | — | クリック時の遷移先 URL |
icon | string | — | 通知アイコン URL |
badge | string | — | バッジアイコン URL |
endpoint | string | — | 指定時はこの購読者のみに送信 |
title と body は必須です。url / icon / badge は https:// の URL のみ許可され、http:// を指定すると 400 INVALID_URL が返ります。
制限とエラー
Section titled “制限とエラー”- ペイロードサイズ:
title/body/url/icon/badgeの合計が 3,072 バイトまで(超過時は 413PAYLOAD_TOO_LARGE) - 月間送信数: Free プランは 30,000 通まで(超過時は 429
MONTHLY_LIMIT_EXCEEDED、upgrade_url付き) - URL 形式:
url/icon/badgeは https:// のみ(400INVALID_URL)
エラーコードの全一覧は エラーコード・制限値 を参照してください。
送信の仕組み
Section titled “送信の仕組み”REST API → Cloudflare Queues → Queue Consumer Worker → ブラウザへ Push通知はリクエスト受信後すぐに Queue に enqueue されます。Consumer Worker が自動起動して非同期に送信するため、大量の購読者がいてもタイムアウトしません。