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

# バッチの作成

> 新しいバッチを開始します。バッチの進行状況を追跡するために使用できる `id` を受け取ります。詳細は[こちら](/api-reference/batches/info)を参照してください。注意: 処理時間はバッチサイズに関係なく一定です。

<Tip>
  **完了時に通知を受け取る:** バッチが完了したときにHTTP POSTを受け取るために、`webhook` パラメータにエンドポイントURLを渡します。詳細は[Webhooks](/api-reference/common/webhooks)を参照してください。
</Tip>

<Tip>
  **カスタムデータを添付する:** `metadata` パラメータを使用してキーと値のペアを保存します。2つのレベルでサポートされています:

  * **バッチレベル** — リクエストボディに
  * **アイテムレベル** — `items` 配列内の各アイテムに

  詳細は[Metadata](/api-reference/common/metadata)を参照してください。
</Tip>


## OpenAPI

````yaml ja/openapi/batches.json POST /v1/batches
openapi: 3.0.3
info:
  title: バッチ API
  version: 1.0.0
servers:
  - url: https://api.olostep.com
security: []
paths:
  /v1/batches:
    post:
      summary: 新しいバッチを開始
      description: 指定されたパラメータで新しいバッチプロセスを開始します。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      custom_id:
                        type: string
                        description: URL の内部ユニーク識別子。
                      url:
                        type: string
                        format: uri
                        description: アイテムの URL。
                      metadata:
                        allOf:
                          - $ref: '#/components/schemas/Metadata'
                        description: >-
                          アイテムレベルのメタデータ。追跡、フィルタリング、または内部システムとの関連付けのために、個々のアイテムにキーと値のペアを添付します。
                    required:
                      - custom_id
                      - url
                  description: バッチで処理されるアイテムの配列。
                country:
                  type: string
                  description: >-
                    バッチ実行の国。ISO 3166-1 alpha-2 コードで提供してください。例: US(USA),
                    IN(India) など。
                parser:
                  type: object
                  properties:
                    id:
                      type: string
                      description: バッチで使用するパーサー。
                  required:
                    - id
                  description: >-
                    このパラメーターを使って使用するパーサーを指定できるよ。パーサーはウェブページから構造化されたコンテンツを抽出するのに便利だよ。Olostepには一般的なウェブページ用のパーサーがいくつか組み込まれていて、自分でパーサーを作成することもできるよ。
                links_on_page:
                  type: object
                  properties:
                    include_links:
                      type: array
                      items:
                        type: string
                      description: >-
                        抽出されたリンクをグロブパターンでフィルタリングするよ。パターンはリンクのURLパスに対してマッチするよ。注意:
                        単一の `*` は `/` を越えないから、"/blog/*" は "/blog/post-1"
                        にマッチするけど、インデックス "/blog" 自体にはマッチしないよ（または "/blog?tag=x"
                        にも、クエリ文字列はパスの一部じゃないからね）。インデックスも含めたいなら、"/blog*" または
                        "{/blog,/blog/**}" を使ってね。
                    exclude_links:
                      type: array
                      items:
                        type: string
                      description: >-
                        抽出されたリンクをグロブパターンでフィルタリングするよ。パターンはリンクのURLパスに対してマッチするよ。注意:
                        単一の `*` は `/` を越えないから、"/blog/*" は "/blog/post-1"
                        にマッチするけど、インデックス "/blog" 自体にはマッチしないよ。
                  description: バッチ内の各ページに存在するすべてのリンクを取得するよ。リンクは常に絶対URLとして返されるよ。
                metadata:
                  $ref: '#/components/schemas/Metadata'
                webhook:
                  type: string
                  format: uri
                  description: >-
                    バッチが完了したときにPOSTリクエストを受け取るためのHTTPS URL。`http://` または
                    `https://`
                    プロトコルを使用して、公開アクセス可能なURLでなければならないよ。localhostやプライベートIPアドレスを指すことはできないよ。[Webhooks](/api-reference/common/webhooks)でペイロードの形式とリトライの動作を確認してね。
              required:
                - items
            example:
              items:
                - custom_id: product-123
                  url: https://example.com/product/123
                  metadata:
                    source: catalog_sync
                    priority: high
                - custom_id: product-456
                  url: https://example.com/product/456
              country: US
              metadata:
                batch_name: Q1 Product Sync
                initiated_by: automation
      responses:
        '200':
          description: バッチが正常に開始されました。
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: バッチ ID
                  object:
                    type: string
                    description: オブジェクトの種類。このエンドポイントでは "batch" だよ。
                  status:
                    type: string
                    description: '`in_progress` または `completed`'
                  created:
                    type: number
                    description: 作成されたエポック
                  total_urls:
                    type: number
                    description: バッチ内のURLの数
                  completed_urls:
                    type: number
                    description: 完了したURLの数
                  parser:
                    type: string
                  country:
                    type: string
                  metadata:
                    $ref: '#/components/schemas/Metadata'
                  webhook:
                    type: string
                    description: 完了通知を受け取るためのWebhook URL
                  credits_consumed:
                    type: integer
                    nullable: true
                    description: このリクエストで消費されたクレジットの数。実行完了後に設定されるよ。クレジットは請求の基準だよ。
                  cost_usd:
                    type: number
                    nullable: true
                    description: >-
                      このリクエストのUSDでの推定コスト。実行完了後に設定されるよ。消費されたクレジットとプランのレートから計算されるよ
                      — 99%の精度だけど、credits_consumedが正確な値だよ。
              example:
                id: batch_abc123def456
                object: batch
                status: in_progress
                created: 1704067200
                total_urls: 2
                completed_urls: 0
                country: US
                metadata:
                  batch_name: Q1 Product Sync
                  initiated_by: automation
        '400':
          description: >-
            不正なパラメーターのために不正なリクエスト。詳細は[Bad
            Request](/api-reference/errors/bad_request)を見てね。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: validation_error
                type: https://docs.olostep.com/api-reference/errors/bad_request
                status: 400
                title: 不正なリクエスト
                detail: >-
                  The 'items' array is required and must contain at least one
                  item.
                created: 1704067200
                metadata: {}
        '401':
          description: >-
            認証情報が欠落しているか無効です。詳細は
            [Unauthorized](/api-reference/errors/unauthorized) を参照してください。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: invalid_api_key
                type: https://docs.olostep.com/api-reference/errors/unauthorized
                status: 401
                title: 認証されていません
                detail: >-
                  Your API key is invalid. Try double-checking it or reaching
                  out to info@olostep.com if you're facing issues.
                created: 1704067200
                metadata: {}
        '402':
          description: >-
            支払いが必要 - クレジットが尽きたよ。詳細は[Payment
            Required](/api-reference/errors/payment_required)を見てね。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: credits_exhausted
                type: https://docs.olostep.com/api-reference/errors/payment_required
                status: 402
                title: 支払いが必要
                detail: >-
                  You have consumed all available credits. Please upgrade your
                  plan from the dashboard: https://www.olostep.com/auth/
                created: 1704067200
                metadata: {}
        '403':
          description: >-
            禁止 -
            この機能へのアクセスが拒否されたよ。詳細は[Forbidden](/api-reference/errors/forbidden)を見てね。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: access_denied
                type: https://docs.olostep.com/api-reference/errors/forbidden
                status: 403
                title: 禁止
                detail: >-
                  You don't have access to this feature. Please reach out to
                  info@olostep.com to get approved
                created: 1704067200
                metadata: {}
        '409':
          description: >-
            冪等性の競合 -
            このキーを持つリクエストが進行中です。詳細は[冪等性エラー](/api-reference/errors/idempotency_error)を参照してください。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: idempotency_key_in_progress
                type: >-
                  https://docs.olostep.com/api-reference/errors/idempotency_error
                status: 409
                title: 冪等性エラー
                detail: >-
                  A request with this idempotency key is currently being
                  processed. Please wait and retry.
                created: 1704067200
                metadata: {}
        '422':
          description: >-
            処理できないエンティティ -
            ビジネスルール違反です。詳細は[処理できないエンティティ](/api-reference/errors/unprocessable_entity)を参照してください。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: idempotency_key_reuse
                type: >-
                  https://docs.olostep.com/api-reference/errors/unprocessable_entity
                status: 422
                title: 処理できないエンティティ
                detail: >-
                  A request with this idempotency key was already made with
                  different parameters. Idempotency keys must be unique per
                  request.
                created: 1704067200
                metadata: {}
        '500':
          description: >-
            内部サーバーエラー。詳細は [Internal Error](/api-reference/errors/internal_error)
            を参照してください。
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                id: error_abc123
                object: error
                code: internal_server_error
                type: https://docs.olostep.com/api-reference/errors/internal_error
                status: 500
                title: 内部サーバーエラー
                detail: An unexpected error occurred
                created: 1704067200
                metadata: {}
      security:
        - Authorization: []
components:
  schemas:
    Metadata:
      type: object
      description: >-
        オブジェクトに関する追加情報を保存するためのキーと値のペアのセット。Stripeのアプローチに従い、検証ルールがあります：最大50キー、キーは最大40文字（角括弧なし）、値は最大500文字、すべての値は文字列として保存されます。
      additionalProperties:
        type: string
        maxLength: 500
        description: メタデータの値（最大500文字）。数値とブール値は自動的に文字列に変換されます。
      maxProperties: 50
      example:
        order_id: '12345'
        customer_name: John Doe
        priority: high
        processed: 'true'
      x-validation-rules:
        max_keys: 50
        key_max_length: 40
        key_forbidden_chars:
          - '['
          - ']'
        value_max_length: 500
        value_types:
          - string
          - number (coerced)
          - boolean (coerced)
    Error:
      type: object
      description: RFC 7807 問題の詳細エラーレスポンス
      properties:
        id:
          type: string
          description: ユニークなエラー識別子
        object:
          type: string
          enum:
            - error
          description: 常に 'error'
        code:
          type: string
          description: 機械可読なエラーコード
        type:
          type: string
          format: uri
          description: 問題タイプを識別するURI参照
        status:
          type: integer
          description: HTTPステータスコード
        title:
          type: string
          description: 短い、人間が読める要約
        detail:
          type: string
          description: 人間が読める説明
        created:
          type: integer
          description: Unixタイムスタンプ
        metadata:
          $ref: '#/components/schemas/Metadata'
        errors:
          type: array
          description: 追加のエラー詳細のオプション配列
          items: {}
      required:
        - id
        - object
        - code
        - type
        - status
        - title
        - detail
        - created
  securitySchemes:
    Authorization:
      type: http
      scheme: bearer
      description: Bearer <token>形式のBearer認証ヘッダー。<token>はあなたの認証トークンです。

````