Overview

Notifications (通知)

+
通知 API

通知 API リファレンス

TaskWorks API の通知関連エンドポイントの詳細ドキュメントです。

# 通知 API リファレンス

TaskWorks API の通知関連エンドポイントの詳細ドキュメントです。すべてのエンドポイントはユーザー固有のデータのみを返します(RLS保護)。

## 認証方式

### ApiKey 認証(推奨)
```
Authorization: ApiKey <token>
```
- 設定 > APIキー管理 から生成
- トークンは一度しか表示されないため安全に保管
- ほとんどのエンドポイントで使用可能

### Bearer トークン認証
```
Authorization: Bearer <token>
```
- サービス間通信で使用
- 一部のエンドポイントで必須(例: /api/v1/blocks/windows)

### Cookie 認証
- 標準のセッションベース認証
- Webクライアントで使用
- Cookie専用エンドポイントで必須

## 共通レスポンス形式

すべての成功レスポンスは以下の構造に従います:
```json
{
  "data": <response_data>,
  "error": null
}
```

すべてのエラーレスポンスは以下の構造に従います:
```json
{
  "error": "<error_type>",
  "message": "<human_readable_message>",
  "code": "<optional_error_code>",
  "context": <optional_additional_context>
}
```

## HTTP ステータスコード

- 200: 成功
- 201: 作成完了
- 400: 不正なリクエスト(検証エラー)
- 401: 未認証(認証が必要)
- 403: 禁止(権限なし)
- 404: 未検出
- 409: 衝突(リソースの競合)
- 500: サーバー内部エラー

## ページネーション

一部のエンドポイントはカーソルベースのページネーションをサポート:
- cursor: 次ページの開始位置
- limit: 返す項目数(1-100、デフォルトはエンドポイントにより異なる)

レスポンス形式:
```json
{
  "data": {
    "items": [...],
    "nextCursor": "string | null",
    "hasMore": boolean
  },
  "error": null
}
```

## API エンドポイント

### 通知(Notifications)

#### POST /api/v1/notifications/send

テスト通知をFCM経由で送信します。

**認証:** Cookie のみ

**リクエストボディ:**
```json
{
  "title": "string",
  "body": "string",
  "data": Object
}
```

**レスポンス スキーマ:**
```json
{
  "data": {
    "success": boolean,
    "messageId": "string | null"
  },
  "error": null
}
```

---

#### GET /api/v1/notifications/token

ユーザーのアクティブなFCMトークンを取得します。

**認証:** Cookie のみ

**レスポンス スキーマ:**
```json
{
  "data": [
    {
      "id": "string",
      "token": "string",
      "isActive": boolean,
      "deviceInfo": Object | null,
      "lastSeenAt": "string | null",
      "createdAt": "string"
    }
  ],
  "error": null
}
```

---

#### POST /api/v1/notifications/token

FCMプッシュトークンを登録/更新します。

**認証:** Cookie のみ

**リクエストボディ:**
```json
{
  "token": "string (required)",
  "deviceInfo": Object | null
}
```

**レスポンス スキーマ:**
```json
{
  "data": {
    "id": "string",
    "token": "string",
    "isActive": boolean,
    "createdAt": "string"
  },
  "error": null
}
```

---

#### DELETE /api/v1/notifications/token

FCMプッシュトークンを無効化します。

**認証:** Cookie のみ

**リクエストボディ:**
```json
{
  "token": "string (required)"
}
```

**レスポンス スキーマ:**
```json
{
  "data": {
    "success": true
  },
  "error": null
}
```