> ## Documentation Index
> Fetch the complete documentation index at: https://docs.notifly.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# キャンペーンをトリガーする

> キャンペーンをトリガーし、指定した送信先に配信します。

> [!NOTE]
>
> プロジェクトのチャネル設定に応じて、アプリプッシュ、Webプッシュ、カカオアリムトーク、カカオフレンドトーク、カカオブランドメッセージ、テキストメッセージ（SMS、LMS、MMS）、メール、LINEのキャンペーンをAPIからトリガーできます。フレンドトークは旧チャネルです。

> [!WARNING]
>
> **送信先の指定方法とパーソナライズ**
>
> 選択したチャネルで対応していない送信先の指定方法を使うと、`400 Bad Request`が返ります。
>
> | チャネル | 送信先の指定方法 |
> | - | - |
> | アプリプッシュ、Webプッシュ | `user-id` |
> | カカオアリムトーク、カカオフレンドトーク、カカオブランドメッセージ、テキストメッセージ | `user-id`、`phone-number` |
> | メール | `user-id`、`email` |
> | LINE | `user-id`、`line-user-id` |
>
> パーソナライズにユーザーデータを使う場合は`user-id`で指定します。ほかの指定方法では、Notiflyはリクエストに含まれる情報を使います。たとえば本文が`{{ user["name"] }} さん、こんにちは`の場合、名前が空になり、受信者には`さん、こんにちは`と表示されます。
>
> イベントパラメーターは、どの指定方法でも使えます。

> [!NOTE]
>
> **重複した送信先の扱い**
>
> アプリプッシュとWebプッシュは、同じデバイストークンに一度だけ送信します。カカオアリムトーク、カカオフレンドトーク、カカオブランドメッセージ、テキストメッセージは電話番号で重複を判定します。メールはメールアドレス、LINEはLINEユーザーIDで判定します。

> [!NOTE]
>
> **400レスポンスに含まれる無効な送信先**
>
> 送信先の検証に失敗すると、`400`レスポンスに`errorDetails`が含まれます。
>
> ```json
> {
>   "code": 400,
>   "success": false,
>   "error": "Bad request: invalid recipients",
>   "errorDetails": {
>     "reasonCode": "INVALID_RECIPIENTS",
>     "channel": "kakao-friendtalk",
>     "invalidRecipientCount": 2,
>     "invalidRecipients": [
>       {
>         "index": 0,
>         "type": "user-id",
>         "userId": "user_001",
>         "reasonCode": "MISSING_PHONE_NUMBER",
>         "source": { "pointer": "/recipients/0/userId" }
>       },
>       {
>         "index": 12,
>         "type": "user-id",
>         "userId": "user_013",
>         "reasonCode": "MISSING_PHONE_NUMBER",
>         "source": { "pointer": "/recipients/12/userId" }
>       }
>     ]
>   }
> }
> ```
>
> | フィールド | 型 | 意味 |
> | - | - | - |
> | `reasonCode` | string | 常に`INVALID_RECIPIENTS`です。 |
> | `channel` | string | キャンペーンのチャネルです。値は`text-message`、`kakao-alimtalk`、`kakao-friendtalk`、`kakao-brand-message`、`email`です。 |
> | `invalidRecipientCount` | number | 無効な送信先の件数です。 |
> | `invalidRecipients` | array | 無効な送信先の一覧です。 |
> | `invalidRecipients[].index` | number | リクエストの`recipients`配列内の位置です。インデックスは0から始まります。 |
> | `invalidRecipients[].type` | string | 常に`user-id`です。 |
> | `invalidRecipients[].userId` | string | リクエストに含まれる`userId`の値です。 |
> | `invalidRecipients[].reasonCode` | string | `MISSING_PHONE_NUMBER`または`MISSING_EMAIL`です。 |
> | `invalidRecipients[].source.pointer` | string | JSON Pointerで示したリクエストフィールドの位置です。 |
>
> | チャネル | 必須フィールド | `reasonCode` |
> | - | - | - |
> | `text-message` | `phone_number` | `MISSING_PHONE_NUMBER` |
> | `kakao-alimtalk` | `phone_number` | `MISSING_PHONE_NUMBER` |
> | `kakao-friendtalk` | `phone_number` | `MISSING_PHONE_NUMBER` |
> | `kakao-brand-message` | `phone_number` | `MISSING_PHONE_NUMBER` |
> | `email` | `email` | `MISSING_EMAIL` |
> | `push-notification`、`web-push-notification` | 連絡先の検証なし | なし |
>
> * `400`レスポンスには`code`、`success`、`error`が含まれます。`errorDetails`が含まれるのは、送信先の検証に失敗した場合だけです。パラメーターが不正な場合やキャンペーンが無効な場合は含まれません。
> * `user-id`で指定したユーザーがNotiflyに登録済みでも、チャネルに必要な連絡先の情報がなければ無効な送信先になります。存在しないユーザーIDはスキップします。
> * `partialSend`が`false`または省略されている場合、無効な送信先が1件でもあるとリクエスト全体が`400`で失敗し、メッセージは配信されません。
> * 再送する場合は、`errorDetails.invalidRecipients`を確認し、無効な送信先をリクエストから削除します。

> [!NOTE]
>
> **有効な送信先に限って配信する**
>
> `partialSend`を`true`にすると、一部の送信先に電話番号やメールアドレスがなくても、有効な送信先に配信します。
>
> * `partialSend: false`（デフォルト）の場合、無効な送信先が1件でもあるとリクエストは`400`で失敗し、どの送信先にも配信されません。
> * `partialSend: true`の場合、有効な送信先に配信し、無効な送信先をレスポンスに含めます。すべての送信先が無効でも`200`が返ります。
>
> 以下は、`partialSend: true`で無効な送信先が2件ある場合のレスポンス例です。
>
> ```json
> {
>   "code": 200,
>   "success": true,
>   "error": null,
>   "errorDetails": {
>     "reasonCode": "INVALID_RECIPIENTS",
>     "channel": "kakao-alimtalk",
>     "invalidRecipientCount": 2,
>     "invalidRecipients": [
>       {
>         "index": 1,
>         "type": "user-id",
>         "userId": "user_002",
>         "reasonCode": "MISSING_PHONE_NUMBER",
>         "source": { "pointer": "/recipients/1/userId" }
>       },
>       {
>         "index": 3,
>         "type": "user-id",
>         "userId": "user_004",
>         "reasonCode": "MISSING_PHONE_NUMBER",
>         "source": { "pointer": "/recipients/3/userId" }
>       }
>     ]
>   }
> }
> ```
>
> `partialSend`に対応するチャネルは、`kakao-alimtalk`、`kakao-friendtalk`、`kakao-brand-message`、`text-message`、`email`です。
>
> > [!NOTE]
> >
> > この連絡先の検証は`user-id`で指定した送信先に適用されます。`type: "phone-number"`または`type: "email"`で直接指定した場合は対象外です。


## OpenAPI

````yaml /ja/api-reference/openapi.yaml post /projects/{projectId}/campaigns/{campaignId}/send
openapi: 3.0.3
info:
  title: Notifly API
  version: 1.0.0
  contact:
    email: contact@notifly.tech
servers:
  - url: https://api.notifly.tech
    description: Notifly APIサーバー
security: []
tags:
  - name: catalog
    x-group: カタログ
paths:
  /projects/{projectId}/campaigns/{campaignId}/send:
    post:
      summary: trigger-campaign
      operationId: triggerCampaign
      parameters:
        - name: projectId
          in: path
          required: true
          schema:
            type: string
          description: プロジェクトIDです。
        - name: campaignId
          in: path
          required: true
          schema:
            type: string
          description: コンソールで確認できるキャンペーンIDです。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - recipients
              properties:
                recipients:
                  type: array
                  items:
                    type: object
                    properties:
                      type:
                        type: string
                        description: >-
                          送信先の指定方法です。デフォルトは`user-id`です。`user-id`、`phone-number`、`email`、`line-user-id`に対応します。
                        enum:
                          - user-id
                          - phone-number
                          - email
                          - line-user-id
                      userId:
                        type: string
                        description: ユーザーIDです。`type`が`user-id`の場合に必須です。
                      phoneNumber:
                        type: string
                        description: 電話番号です。`type`が`phone-number`の場合に必須です。
                      email:
                        type: string
                        description: メールアドレスです。`type`が`email`の場合に必須です。
                      lineUserId:
                        type: string
                        description: LINEユーザーIDです。`type`が`line-user-id`の場合に必須です。
                      eventParams:
                        type: object
                        description: メッセージのパーソナライズに使うイベントパラメーターです。
                  description: 送信先のリストです。最大1,000件まで指定できます。
                partialSend:
                  type: boolean
                  default: false
                  description: >-
                    `true`の場合、一部の送信先に必須の電話番号やメールアドレスがなくても、有効な送信先に配信します。レスポンスには無効な送信先のリストが含まれます。`false`または省略時は、無効な送信先が1件でもあるとリクエスト全体が失敗します。
            examples:
              basicRequest:
                summary: 通常の配信リクエスト
                value:
                  recipients:
                    - type: phone-number
                      phoneNumber: 010-1234-5678
              partialSendRequest:
                summary: 有効な送信先に限って配信するリクエスト
                value:
                  recipients:
                    - userId: user_001
                    - userId: user_002
                  partialSend: true
      responses:
        '200':
          description: >-
            キャンペーンをトリガーしました。`partialSend`が`true`で無効な送信先がある場合、レスポンスに`errorDetails`が含まれます。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  success:
                    type: boolean
                  error:
                    type: string
                    nullable: true
                  errorDetails:
                    type: object
                    description: '`partialSend`が`true`で無効な送信先がある場合に含まれます。'
                    properties:
                      reasonCode:
                        type: string
                        enum:
                          - INVALID_RECIPIENTS
                      channel:
                        type: string
                        description: キャンペーンのチャネルです。
                      invalidRecipientCount:
                        type: integer
                        description: 無効な送信先の件数です。
                      invalidRecipients:
                        type: array
                        description: 無効な送信先の詳細です。
                        items:
                          type: object
                          properties:
                            index:
                              type: integer
                            type:
                              type: string
                            userId:
                              type: string
                            reasonCode:
                              type: string
                              enum:
                                - MISSING_PHONE_NUMBER
                                - MISSING_EMAIL
                            source:
                              type: object
                              properties:
                                pointer:
                                  type: string
              examples:
                successNoInvalid:
                  summary: すべての送信先が有効な場合（errorDetailsなし）
                  value:
                    code: 200
                    success: true
                    error: null
                partialSendWithInvalid:
                  summary: 無効な送信先を含む一部配信
                  value:
                    code: 200
                    success: true
                    error: null
                    errorDetails:
                      reasonCode: INVALID_RECIPIENTS
                      channel: kakao-alimtalk
                      invalidRecipientCount: 2
                      invalidRecipients:
                        - index: 1
                          type: user-id
                          userId: user_002
                          reasonCode: MISSING_PHONE_NUMBER
                          source:
                            pointer: /recipients/1/userId
                        - index: 3
                          type: user-id
                          userId: user_004
                          reasonCode: MISSING_PHONE_NUMBER
                          source:
                            pointer: /recipients/3/userId
        '400':
          description: リクエストが不正です。送信先の検証に失敗した場合にだけ、`errorDetails`が含まれます。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  success:
                    type: boolean
                  error:
                    type: string
                  errorDetails:
                    type: object
                    description: >-
                      送信先の検証に失敗した場合にだけ含まれます。たとえば、`user-id`で指定した送信先に必須の連絡先がない場合です。
                    required:
                      - reasonCode
                      - channel
                      - invalidRecipientCount
                      - invalidRecipients
                    properties:
                      reasonCode:
                        type: string
                        enum:
                          - INVALID_RECIPIENTS
                        description: 送信先の検証エラーを示すコードです。
                      channel:
                        type: string
                        description: キャンペーンのチャネルです。
                      invalidRecipientCount:
                        type: integer
                        description: 無効な送信先の件数です。
                      invalidRecipients:
                        type: array
                        description: 無効な送信先の詳細です。
                        items:
                          type: object
                          required:
                            - index
                            - type
                            - userId
                            - reasonCode
                            - source
                          properties:
                            index:
                              type: integer
                              description: リクエストの`recipients`配列内の位置です。インデックスは0から始まります。
                            type:
                              type: string
                              enum:
                                - user-id
                              description: 送信先の指定方法です。
                            userId:
                              type: string
                              description: リクエストに含まれる`userId`の値です。
                            reasonCode:
                              type: string
                              enum:
                                - MISSING_PHONE_NUMBER
                                - MISSING_EMAIL
                              description: 不足している必須の連絡先の種類です。
                            source:
                              type: object
                              required:
                                - pointer
                              properties:
                                pointer:
                                  type: string
                                  description: JSON Pointerで示したリクエストフィールドの位置です。
              examples:
                generalBadRequest:
                  summary: 一般的な400レスポンス（errorDetailsなし）
                  value:
                    code: 400
                    success: false
                    error: 'Bad request: some-error-message'
                invalidRecipients:
                  summary: 送信先の検証エラー（errorDetailsあり）
                  value:
                    code: 400
                    success: false
                    error: 'Bad request: invalid recipients'
                    errorDetails:
                      reasonCode: INVALID_RECIPIENTS
                      channel: kakao-friendtalk
                      invalidRecipientCount: 2
                      invalidRecipients:
                        - index: 0
                          type: user-id
                          userId: user_001
                          reasonCode: MISSING_PHONE_NUMBER
                          source:
                            pointer: /recipients/0/userId
                        - index: 12
                          type: user-id
                          userId: user_013
                          reasonCode: MISSING_PHONE_NUMBER
                          source:
                            pointer: /recipients/12/userId
        '401':
          description: トークンが期限切れであるか、認証情報が無効です。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                code: 401
                success: false
                error: 'Unauthorized: Invalid token'
        '405':
          description: サポートされていないHTTPメソッドです。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                code: 405
                success: false
                error: 'Method not allowed: some-error-message'
        '413':
          description: リクエスト本文のサイズが上限を超えています。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                code: 413
                success: false
                error: 'Payload too large: some-error-message'
        '500':
          description: Notiflyのサーバーエラーです。500エラーが続く場合は、Notiflyのサポートにお問い合わせください。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                code: 500
                success: false
                error: some-error-message
        '501':
          description: この機能は現在利用できません。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  success:
                    type: boolean
                  error:
                    type: string
              example:
                code: 501
                success: false
                error: 'Not implemented: some-error-message'
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: '`POST /authenticate`で発行したトークンをBearer形式で送信します。'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.