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

# 配信メッセージ作成

> **プレビュー機能。仕様は今後変更される可能性があります。** 指定シナリオに配信メッセージを新規作成します。

- `channel` と `type` は作成後に変更できません。
- `status` を `reserved`（予約）にすると、配信安全制御・DKIM/SMS前提チェックが実行されます。
- 媒体に応じて原稿オブジェクト（`mail` / `line` / `sms`）を指定します。
- `channel=mail` のメール本文には配信解除URL（`%cancel%` または `%cancelall%`）を必ず含めてください。含めない場合はバリデーションエラーになります。
- `channel=action` の場合は原稿オブジェクト不要。`status=reserved` 時は `action_id` が必須です。


`POST`

```
https://api.utage-system.com/v1/accounts/{account_id}/scenarios/{scenario_id}/messages
```

<Note>この機能はプレビュー版です。仕様が変更される場合があります。</Note>


## OpenAPI

````yaml POST /accounts/{account_id}/scenarios/{scenario_id}/messages
openapi: 3.0.3
info:
  title: UTAGE API
  description: |
    UTAGEのパブリックAPIです。ファネル、配信アカウント、シナリオ、メディアなどのリソースをプログラムから操作できます。

    ## 認証
    すべてのリクエストにAPIキーによるBearer認証が必要です（要素タイプエンドポイントを除く）。

    ```
    Authorization: Bearer {api_key}
    ```

    APIキーはUTAGE管理画面から発行できます。

    ## レート制限
    リクエスト数には以下の制限があります。

    | 分間上限 | 日間上限 |
    |----------|----------|
    | 60リクエスト/分 | 10,000リクエスト/日 |

    レスポンスヘッダーで現在の使用状況を確認できます。

    | ヘッダー | 説明 |
    |----------|------|
    | X-RateLimit-Limit | 分間の上限値 |
    | X-RateLimit-Remaining | 分間の残りリクエスト数 |
    | X-RateLimit-Reset | 制限がリセットされるUNIXタイムスタンプ |

    上限を超えた場合は `429 Too Many Requests` が返されます。

    ## エラーレスポンス
    エラー時は以下の形式で返されます。

    ```json
    {
      "error": {
        "code": "error_code",
        "message": "エラーメッセージ"
      }
    }
    ```
  version: '1.0'
  contact:
    name: UTAGE サポート
servers:
  - url: https://api.utage-system.com/v1
    description: UTAGE API
security:
  - BearerAuth: []
tags:
  - name: ファネル
    description: ファネルの作成・更新・一覧取得
  - name: ステップ
    description: ファネル内のステップの作成・更新・並び替え
  - name: ページ
    description: ステップ内のページの作成・更新・取得・削除
  - name: 配信アカウント
    description: 配信アカウントの作成・一覧取得
  - name: シナリオ
    description: シナリオの作成・一覧取得
  - name: メディア
    description: 動画・音声・通常メディアの一覧取得とアップロード
  - name: 要素タイプ
    description: ファネルページ・HTMLメールの要素タイプ定義、LINEメッセージタイプ・配信条件タイプの取得（認証不要）
  - name: ファネル統計
    description: ファネルの集計データ・登録者・登録経路の取得（プレビュー）
  - name: 配信メッセージ
    description: 配信メッセージの作成・更新・テスト送信・配信統計、置き換え文字の取得（プレビュー）
  - name: 読者
    description: 読者の作成・更新・取得、ラベル・配信履歴・開封/クリック履歴の取得（プレビュー）
  - name: LINE
    description: LINE友だち・カスタム送信者・1対1チャット・テンプレートの操作（プレビュー）
  - name: ラベル・共通読者・登録経路
    description: ラベル・共通読者・アクション・登録経路の操作（プレビュー）
paths:
  /accounts/{account_id}/scenarios/{scenario_id}/messages:
    post:
      tags:
        - 配信メッセージ
      summary: 配信メッセージ作成
      description: >
        **プレビュー機能。仕様は今後変更される可能性があります。** 指定シナリオに配信メッセージを新規作成します。


        - `channel` と `type` は作成後に変更できません。

        - `status` を `reserved`（予約）にすると、配信安全制御・DKIM/SMS前提チェックが実行されます。

        - 媒体に応じて原稿オブジェクト（`mail` / `line` / `sms`）を指定します。

        - `channel=mail` のメール本文には配信解除URL（`%cancel%` または
        `%cancelall%`）を必ず含めてください。含めない場合はバリデーションエラーになります。

        - `channel=action` の場合は原稿オブジェクト不要。`status=reserved` 時は `action_id`
        が必須です。
      operationId: createMessage
      parameters:
        - $ref: '#/components/parameters/AccountId'
        - name: scenario_id
          in: path
          required: true
          description: シナリオID
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MessageCreateRequest'
      responses:
        '201':
          description: 作成された配信メッセージ
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/MessageDetail'
                  warnings:
                    type: array
                    description: |
                      予約（reserved）化時に検出された警告（DKIM未設定・配信安全制御など）。
                      警告がある場合のみ返されることがあります。
                    items:
                      type: string
        '400':
          description: >
            リクエストが不正です。`channel=sms` かつ `status=reserved`
            で予約する際に、SMS未設定（`sms_not_configured`）、SMS送信クレジット不足（`sms_no_credit`）の場合に返ります。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/ValidationError'
        '429':
          $ref: '#/components/responses/RateLimitExceeded'
components:
  parameters:
    AccountId:
      name: account_id
      in: path
      required: true
      description: アカウントID
      schema:
        type: string
  schemas:
    MessageCreateRequest:
      type: object
      description: |
        配信メッセージ作成リクエスト。`type` に応じて送信タイミング系フィールドを指定します。
        送信タイミングの詳細な指定方法は MCPツール（message_create）の説明も参照してください。
      required:
        - channel
        - type
      properties:
        channel:
          type: string
          enum:
            - mail
            - line
            - sms
            - action
          description: 媒体（作成後に変更不可）
        type:
          type: string
          enum:
            - broadcast
            - step
            - reminder
          description: 配信タイプ（作成後に変更不可）
        status:
          type: string
          enum:
            - draft
            - reserved
          default: draft
          description: |
            ステータス。`reserved`（予約）にすると配信安全制御・DKIM/SMS前提チェックが実行されます。
        title:
          type: string
          maxLength: 255
          description: 管理名称
        use_ab_test:
          type: boolean
          description: A/Bテスト使用
        send_type:
          type: string
          description: |
            送信タイプ。broadcast: `immediately`（即時）/`scheduled`（日時指定）。
            step: `immediately` / `scheduled`（日数指定）/`scheduled_addition`（追加配信）。
        send_date:
          type: string
          format: date
          description: 送信日（broadcast用、YYYY-MM-DD）
        send_day:
          type: integer
          description: |
            送信日数（step / reminder 用）。step: 登録からの日数（0=当日）。
            reminder: 基準日からの日数（0以上）。
        send_hour:
          type: integer
          minimum: 0
          maximum: 23
          description: 送信時（0-23）
        send_min:
          type: integer
          minimum: 0
          maximum: 59
          description: 送信分（0-59）
        send_timing:
          type: string
          enum:
            - before
            - after
            - today
            - addition_before
            - addition_after
          description: |
            送信タイミング（reminder用）。before=基準日の前、after=基準日の後、today=基準日当日、
            addition_before/addition_after=追加配信。
        base_date:
          type: string
          description: 基準日の読者項目名（reminder用）。置き換え文字一覧の reader_item から取得。
        step_send_type:
          type: string
          enum:
            - none
            - immediately
          description: |
            ステップ送信タイプ（step用）。none=指定日時に送信、immediately=登録直後に即時送信。
        mail:
          allOf:
            - $ref: '#/components/schemas/MailContent'
          description: メール原稿（channel=mail 時に必須）
        line:
          allOf:
            - $ref: '#/components/schemas/LineContent'
          description: LINE原稿（channel=line 時に必須）
        sms:
          allOf:
            - $ref: '#/components/schemas/SmsContent'
          description: SMS原稿（channel=sms 時に必須）
        action_id:
          type: string
          description: 配信後に実行するアクションID（channel=action かつ status=reserved 時に必須）
        shorten_type:
          type: string
          enum:
            - shorten_url
            - original_url
          default: shorten_url
          description: 'URL置換方法（shorten_url: 置換URLを表示、original_url: 元のURLを表示）'
        shorten_domain:
          type: string
          description: URL置換ドメイン
        conditions:
          type: array
          description: |
            配信条件。グループ間はOR結合、グループ内の rules はAND結合。
            使用可能な key / condition / value は配信条件タイプ定義を参照してください。
          items:
            type: object
        url_actions:
          type: array
          description: URLアクションの配列
          items:
            type: object
    MessageDetail:
      type: object
      description: >
        配信メッセージの詳細。共通フィールドに加え、`type` に応じた送信タイミング系フィールド

        （`send_type` / `send_date` / `send_day` / `send_hour` / `send_min` /
        `base_date` /

        `send_timing` / `step_send_type` 等）と、`channel` に応じた原稿（`mail` / `line` /
        `sms`）、

        `url_actions` を含みます。
      properties:
        id:
          type: string
          description: メッセージID
        channel:
          type: string
          enum:
            - mail
            - line
            - sms
            - action
          description: 媒体
        type:
          type: string
          enum:
            - broadcast
            - step
            - reminder
          description: 配信タイプ
        status:
          type: string
          enum:
            - draft
            - reserved
            - sending
            - completed
          description: ステータス
        title:
          type: string
          nullable: true
          description: 管理名称
        mail:
          type: object
          nullable: true
          description: メール原稿全体（channel=mail のとき）
        line:
          type: object
          nullable: true
          description: LINE原稿（channel=line のとき）。{sender_id, messages[]}
          properties:
            sender_id:
              type: string
              nullable: true
              description: 送信者ID
            messages:
              type: array
              description: LINEメッセージの配列
              items:
                type: object
        sms:
          type: object
          nullable: true
          description: SMS原稿（channel=sms のとき）
        url_actions:
          type: array
          description: URLアクションの配列
          items:
            type: object
      additionalProperties: true
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: エラーコード
            message:
              type: string
              description: エラーメッセージ
            details:
              type: object
              nullable: true
              description: エラーの補足情報（retry_afterやフィールド別エラー等）。エラー種別により含まれる場合があります。
    MailContent:
      type: object
      description: |
        メール原稿（channel=mail のとき指定）。本文には配信解除URL（`%cancel%` または
        `%cancelall%`）を必ず含めてください。
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - plain_text
            - html
          description: '種類（plain_text: テキスト、html: HTML）'
        from_name:
          type: string
          description: 送信者名（status=reserved 時は必須）
        from_mail:
          type: string
          description: 送信者メールアドレス（status=reserved 時は必須）
        subject:
          type: string
          description: 件名（status=reserved 時は必須）
        text:
          type: string
          description: 本文（type=plain_text 時に必須）
        elements:
          type: array
          description: |
            HTMLメール要素の配列（type=html 時に必須）。各要素のプロパティ名は要素タイプ定義
            （`/element-types/mail`、`/element-types/mail/properties`）で確認してください。
          items:
            type: object
        width:
          type: integer
          description: メール全体の幅（px）（type=html 時の任意のレイアウト設定）
        bordertype:
          type: string
          description: 枠線のタイプ（type=html 時の任意のレイアウト設定）
        background_color:
          type: string
          description: 背景色（type=html 時の任意のレイアウト設定）
        padding_y:
          type: integer
          description: 上下の余白（px）（type=html 時の任意のレイアウト設定）
        padding_x:
          type: integer
          description: 左右の余白（px）（type=html 時の任意のレイアウト設定）
        subject_pattern_b:
          type: string
          maxLength: 255
          description: パターンB件名（use_ab_test=1 時に指定。status=reserved 時は必須）
        preview_text:
          type: string
          maxLength: 150
          description: プレビューに表示するテキスト
    LineContent:
      type: object
      description: LINE原稿（channel=line のとき指定）。タイプ別の詳細は LINEメッセージタイプ定義を参照。
      properties:
        sender_id:
          type: string
          description: 送信者ID
        messages:
          type: array
          minItems: 1
          maxItems: 5
          description: LINEメッセージの配列（1〜5件）
          items:
            type: object
    SmsContent:
      type: object
      description: SMS原稿（channel=sms のとき指定）
      properties:
        message:
          type: string
          maxLength: 360
          description: 本文（最大360文字、絵文字不可）
  responses:
    Unauthorized:
      description: 認証エラー。APIキーが無効または未指定。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: unauthorized
              message: 認証に失敗しました
    NotFound:
      description: 指定されたリソースが見つかりません。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: not_found
              message: リソースが見つかりません
    ValidationError:
      description: バリデーションエラー。リクエストパラメータが不正。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: validation_error
              message: バリデーションエラーが発生しました
    RateLimitExceeded:
      description: レート制限超過。時間を空けて再試行してください。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: rate_limit_exceeded
              message: リクエスト上限を超えました。しばらく時間を空けて再試行してください
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: APIキーをBearerトークンとして指定

````