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

# Webhookを作成

> 新しいWebhookを登録します。
- 複数のWebhookを登録可能
- 登録時に署名シークレットが返却されます

**重要**: シークレットはこのレスポンスでのみ表示されます。安全に保管してください。

## Webhookイベントタイプ

| イベントタイプ | 説明 |
|-----------|-------------|
| `order.antiAi.completed` | Anti-AI処理が完了 |
| `order.antiAi.failed` | Anti-AI処理が失敗 |
| `order.watermarkEmbed.completed` | watermark 埋め込みが完了 |
| `order.watermarkEmbed.failed` | watermark 埋め込みが失敗 |
| `order.watermarkExtract.completed` | watermark 抽出が完了 |
| `order.watermarkExtract.failed` | watermark 抽出が失敗 |

## 署名検証

Webhookリクエストには `X-MoriBiz-Signature` ヘッダーが含まれます。
署名は、登録時に発行されたシークレットを使用してHMAC-SHA256で生成されます。

```javascript
const crypto = require('crypto');
const signature = crypto.createHmac('sha256', secret)
  .update(JSON.stringify(payload))
  .digest('hex');
```

## リトライポリシー

- 最大3回リトライ
- 指数バックオフ（1秒、2秒、4秒）
- 成功レスポンス: 2xxステータスコード



## OpenAPI

````yaml ja/api-reference/openapi.yaml POST /api/v2/orders/webhooks
openapi: 3.0.0
info:
  title: BIZ MORI API
  version: 2.0.0
  description: >-
    BIZ MORI API は、デジタルコンテンツ保護のための4つのコアサービスを提供します:

    - **Anti-AI**: 画像をAI学習から保護

    - **Watermark Embed**: 画像に不可視のデジタル watermark を埋め込み

    - **Watermark Extract**: 画像から watermark を抽出・検証

    - **AI Detection**: 画像がAI生成かどうかを検知

    - **テストAPIキー**: `sk_test_`
    プレフィックスのキーは同じBearer認証を使用し、実際の処理サービスの実行やクレジットの消費なしに注文ライフサイクルを検証できます。テストアップロードの内容は破棄され、結果ファイルは作成されません
  contact:
    name: BIZ MORI サポート
    email: support@bizmori.com
servers:
  - url: https://api.bizmori.com
    description: 本番環境
security: []
tags:
  - name: Anti-AI
    description: Anti-AI画像保護の注文
  - name: Watermark Embed
    description: watermark 埋め込みの注文
  - name: Watermark Extract
    description: watermark 抽出の注文
  - name: AI Detection
    description: AI生成画像検知の注文
  - name: Orders
    description: 注文の照会と管理
  - name: Webhooks
    description: Webhookの設定とイベント
paths:
  /api/v2/orders/webhooks:
    post:
      tags:
        - Webhooks
      summary: Webhookを作成
      description: |-
        新しいWebhookを登録します。
        - 複数のWebhookを登録可能
        - 登録時に署名シークレットが返却されます

        **重要**: シークレットはこのレスポンスでのみ表示されます。安全に保管してください。

        ## Webhookイベントタイプ

        | イベントタイプ | 説明 |
        |-----------|-------------|
        | `order.antiAi.completed` | Anti-AI処理が完了 |
        | `order.antiAi.failed` | Anti-AI処理が失敗 |
        | `order.watermarkEmbed.completed` | watermark 埋め込みが完了 |
        | `order.watermarkEmbed.failed` | watermark 埋め込みが失敗 |
        | `order.watermarkExtract.completed` | watermark 抽出が完了 |
        | `order.watermarkExtract.failed` | watermark 抽出が失敗 |

        ## 署名検証

        Webhookリクエストには `X-MoriBiz-Signature` ヘッダーが含まれます。
        署名は、登録時に発行されたシークレットを使用してHMAC-SHA256で生成されます。

        ```javascript
        const crypto = require('crypto');
        const signature = crypto.createHmac('sha256', secret)
          .update(JSON.stringify(payload))
          .digest('hex');
        ```

        ## リトライポリシー

        - 最大3回リトライ
        - 指数バックオフ（1秒、2秒、4秒）
        - 成功レスポンス: 2xxステータスコード
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WebhookCreateRequest'
      responses:
        '200':
          description: Webhookの作成に成功しました
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      id:
                        type: integer
                        description: Webhook ID
                      name:
                        type: string
                        description: Webhook名
                      secret:
                        type: string
                        description: |-
                          Webhook署名シークレット。
                          **警告**: この値は再取得できません。安全に保管してください。
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
      security:
        - BearerAuth: []
      x-codeSamples:
        - lang: curl
          label: cURL
          source: |-
            curl -X POST https://api.bizmori.com/api/v2/orders/webhooks \
              -H "Authorization: Bearer YOUR_API_TOKEN" \
              -H "Content-Type: application/json" \
              -d '{
                "name": "My Webhook",
                "url": "https://example.com/webhook"
              }'
        - lang: javascript
          label: JavaScript
          source: >-
            const response = await
            fetch('https://api.bizmori.com/api/v2/orders/webhooks', {
              method: 'POST',
              headers: {
                'Authorization': 'Bearer YOUR_API_TOKEN',
                'Content-Type': 'application/json'
              },
              body: JSON.stringify({
                name: 'My Webhook',
                url: 'https://example.com/webhook'
              })
            });

            const data = await response.json();

            // Save data.data.secret securely — it won't be shown again
        - lang: python
          label: Python
          source: |-
            import requests

            response = requests.post(
                'https://api.bizmori.com/api/v2/orders/webhooks',
                headers={'Authorization': 'Bearer YOUR_API_TOKEN'},
                json={
                    'name': 'My Webhook',
                    'url': 'https://example.com/webhook'
                }
            )
            data = response.json()
            # Save data['data']['secret'] securely — it won't be shown again
components:
  schemas:
    WebhookCreateRequest:
      type: object
      required:
        - url
      properties:
        name:
          type: string
          maxLength: 100
          description: Webhook名（識別用）
        url:
          type: string
          format: uri
          description: Webhookエンドポイント URL
          example: https://example.com/webhook
    ErrorResponse:
      type: object
      properties:
        code:
          type: string
          description: エラーコード
  responses:
    BadRequest:
      description: 不正なリクエスト
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: VALIDATION_FAILED
    Unauthorized:
      description: 認証失敗
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: AUTH_NOT_AUTHENTICATED
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        外部クライアントアクセス用のBearer APIキー。本番キーは `sk_` プレフィックスを使用し、テストキーは `sk_test_`
        プレフィックスを使用して、処理やクレジット消費なしに注文ライフサイクルを検証します。

````