REST API

ベース URL: https://nesh.kkweb.io/api/v1/projects/<projectId>

Subscribe

ブラウザが push subscription を発行した後、SDK から呼ばれます。CORS 対応、認証なし。

POST /api/v1/projects/<projectId>
Content-Type: application/json

{
  "endpoint": "https://fcm.googleapis.com/...",
  "keys": { "p256dh": "...", "auth": "..." },
  "userId": "alice"            // optional
}

→ 201 { "ok": true }

1 IP × プロジェクト × アクションあたり 60 リクエスト/分のレート制限。新規エンドポイントには無料枠の購読者数上限も適用されます (既存エンドポイントの更新は常に可能)。

Unsubscribe

DELETE /api/v1/projects/<projectId>?endpoint=<urlencoded-endpoint>

→ 200 { "ok": true }

通知を送信

サーバー間通信。プロジェクトの API キーカードの Bearer トークン (形式: nesh_sk_…) を使用。同期 — レスポンスに配信件数が含まれます。

POST /api/v1/projects/<projectId>/notifications
Authorization: Bearer nesh_sk_…
Content-Type: application/json

{
  "title":   "Hello",
  "body":    "From the API",
  "url":     "https://example.com",
  "icon":    "https://example.com/icon-192.png",
  "image":   "https://example.com/hero.jpg",
  "badge":   "https://example.com/badge-72.png",
  "userIds": ["alice", "bob"]    // optional — omit to broadcast
}

→ 201 {
  "id":        "uuid",
  "attempted": 12,
  "delivered": 11,
  "removed":   1,
  "failed":    0
}

無料枠では月間送信上限 (プロジェクトあたり 10,000 通 / UTC 月) が適用されます。超過時は 429 を返します。

イベント追跡 (SDK / SW)

SDK v0.6+ では Service Worker が shown / clicked ビーコンを自動で POST します。通常はコードから呼ぶ必要はありません。

POST /api/v1/projects/<projectId>/notifications/<notificationId>/events
Content-Type: application/json

{ "type": "shown" }   // or "clicked"

→ 200 { "ok": true }