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

# SKU で Resend を作成

> Enterprise-only. Creates a resend by supplying warehouse-scoped SKU quantities instead of explicit return inventory IDs. The service selects eligible pending return inventory records itself (LIFO by default), then reuses the standard create-resend workflow. The whole request is processed atomically — either every requested unit is allocated and one resend is created, or nothing is.

<Warning>
  このページはAIによって自動翻訳されています。API技術仕様は英語が正式です。不明点がある場合は[英語版](/api-reference/resend/create-resend-by-sku)を参照してください。
</Warning>

<Note>
  これは **Enterprise 専用** 機能で、SKU 在庫モジュールが有効な Return Helper Enterprise のお客様のみ利用できます。有効化されていないアカウントからのリクエストは拒否されます。詳しくは [enterprise-solution@returnhelper.com](mailto:enterprise-solution@returnhelper.com) までお問い合わせください。
</Note>

明示的な返品在庫 ID ではなく、**倉庫単位の SKU 数量**を指定して resend を作成します。

リクエストは**アトミック**に処理されます。要求されたすべての単位が割り当てられて 1 件の resend が作成されるか、何も作成されずリクエストが失敗するかのいずれかです。部分的な resend は発生しません。

<h2 id="when-to-use-this-vs-create-resend-order">
  Create resend order ではなく本エンドポイントを使う場合
</h2>

* SKU と数量で在庫を管理しており、個々の `returnInventoryId` 値を扱いたくない場合は、**SKU で Resend を作成**を使用します。
* resend したい特定の `returnInventoryId` 値をすでに保持している場合（例: `newInventoryCreated` webhook からキャッシュ）は、[Create resend order](/ja/api-reference/resend/create-resend-order) を使用します。

<h2 id="prerequisites">
  前提条件
</h2>

* アカウントで SKU 在庫モジュール（Enterprise）が有効になっている。
* その倉庫に、要求された各 SKU について resend 対象として十分な在庫がある。まず [SKU 在庫を検索](/ja/api-reference/skuinventory/search-sku-inventory)（`availableQuantity`）でサマリーを確認してください。ただし、サマリーチェックの通過は保証ではありません（下記参照）。
* `shipmentServiceType` は **Shipment Service Type**（**Return Service Type ではありません**）。有効なコードは [Warehouse で利用可能な Shipment Service Types を取得](/ja/api-reference/shipmentservicetype/get-available-shipment-service-types-for-warehouse) から取得してください。

<h2 id="how-selection-works">
  選択の仕組み
</h2>

割り当ては 3 段階で行われ、権威を持つのは最後の段階のみです。

1. **検証。** リクエスト行が正規化され（SKU の trim + 大文字化）、重複する SKU が結合されます。検証は `warehouseId` + 正規化後 SKU ごとに `availableQuantity` をチェックします。これを通過しても、サマリー上十分に見えることを確認するだけで、**何も予約・割り当てされません**。
2. **選択。** システムは `warehouseId` と正規化 SKU に一致し、resend 対象となる実際の返品在庫レコードを照会し、[ピックアップ戦略](#pick-up-strategy)に従って要求された数量をちょうど選択します。対象レコードが要求数より少ない場合、リクエスト全体が拒否されます。
3. **割り当て。** トランザクション内で、選択された行をロックして再チェックします。いずれかが対象外になっていればトランザクションをロールバックし、リクエストが失敗します。そうでなければ、選択されたすべてのレコードが resend / in-progress に進められ、同じトランザクション内で resend が作成されます。

<Warning>
  `SkuInventory.availableQuantity` は**事前チェックであり、予約ではありません。** 複数の並行リクエストが同じサマリーチェックを通過し得ますが、基礎レコードのロードとロックに成功したリクエストのみがコミットします。他は検証エラーで失敗し、再試行できます。ロックされた割り当てが常に最終的な権威です。
</Warning>

<h2 id="eligibility-rules">
  対象条件
</h2>

返品在庫レコードは、次の条件をすべて満たす場合にのみ選択対象になります。

* 要求された `warehouseId` と正規化後 SKU に一致する。
* `handlingStatusCode` = **pending**。
* resend / in-progress に遷移できる。かつ
* **保留中の VAS がない**（未完了の VAS Split を含む）。

対象条件がステータスベースであるため、MySQL 上の対象件数はサマリーの `availableQuantity` より**少なくなる**ことがあります（後者は保留中の VAS を持つレコードを数える場合があります）。その場合、対象外の項目を resend するのではなく、リクエストは fail-closed で失敗します。

<h2 id="pick-up-strategy">
  ピックアップ戦略
</h2>

選択はデフォルトで **LIFO** を使用します。最新の `createOn` を優先し、タイブレークには最大の返品在庫 ID を用います。この戦略はファクトリの背後に置かれており、割り当てロジックを変更せずに将来 FIFO に切り替えられます。

<h2 id="errors-and-retries">
  エラーと再試行
</h2>

* 検証失敗は HTTP 200 と `meta.status: 400` で返されます（標準のソフトエラーエンベロープ。[エラー処理](/ja/introduction#error-handling)を参照）。
* ある SKU の可用量が不足している場合、リクエストは**全体として**拒否されます。セキュリティのため、エラーは残りの可用量を**開示しません**。
* 並行リクエストが同じ在庫を奪い合う場合、レコードのロックに失敗したリクエストは拒否され、再試行できます。

<h2 id="related">
  関連
</h2>

* [SKU 在庫を検索](/ja/api-reference/skuinventory/search-sku-inventory) — リクエスト前に `availableQuantity` を確認します。
* [Create resend order](/ja/api-reference/resend/create-resend-order) — 明示的な返品在庫 ID で resend します。ラベル生成（自動 vs 手動サービスタイプ）とキャンセル締切もカバーしており、ここで作成される resend にも適用されます。
* [Resend Order をキャンセル](/ja/api-reference/resend/cancel-resend-order) — 倉庫が出荷する前に中止します。
* [Webhooks](/ja/webhooks) — resend-status-update イベントがライフサイクルの変更をエンドポイントに配信します。


## OpenAPI

````yaml post /api/Resend/createResendBySku
openapi: 3.1.0
info:
  title: Return Helper API
  description: API documentation for Return Helper — covering User and Public endpoints.
  version: 1.0.0
servers:
  - url: https://api.returnshelper.com/uat/user
    description: Sandbox — User API
  - url: https://api.returnshelper.com/uat/public
    description: Sandbox — Public API
  - url: https://api.returnhelpercentre.com/v1/user
    description: Production — User API
  - url: https://api.returnhelpercentre.com/v1/public
    description: Production — Public API
  - url: https://api.returnhelperchina.com/user
    description: Production — User API (China)
security:
  - ApiKey: []
    ApiToken: []
paths:
  /api/Resend/createResendBySku:
    post:
      tags:
        - Resend
      summary: Create resend by SKU
      description: >-
        Enterprise-only. Creates a resend by supplying warehouse-scoped SKU
        quantities instead of explicit return inventory IDs. The service selects
        eligible pending return inventory records itself (LIFO by default), then
        reuses the standard create-resend workflow. The whole request is
        processed atomically — either every requested unit is allocated and one
        resend is created, or nothing is.
      operationId: ReturnUserApi_CreateResendBySku
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateResendBySkuRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateResendBySkuResponse'
        '401':
          description: >-
            Authentication failed. Returned when the `x-rr-apikey` or
            `x-rr-apitoken` header is missing or invalid. The body uses the
            standard `ApiResponse` envelope with `meta.error.message` describing
            the auth failure.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponse'
      security:
        - ApiKey: []
          ApiToken: []
      servers:
        - url: https://api.returnshelper.com/uat/user
          description: Sandbox — User API
components:
  schemas:
    CreateResendBySkuRequest:
      type: object
      description: >-
        Create a resend by warehouse-scoped SKU quantities. `companyName` is not
        part of this request.
      properties:
        warehouseId:
          type: integer
          format: int32
          description: >-
            Warehouse to fulfil the resend from. Must be greater than 0 and
            owned by the authenticated account. All selected inventory comes
            from this single warehouse.
        shipmentServiceType:
          type: string
          description: >-
            Shipment service type code (not a return service type). Non-`others`
            values are validated against the available shipment service and
            service zone for the warehouse and destination.
        itemList:
          type: array
          items:
            $ref: '#/components/schemas/CreateResendBySkuItem'
          description: >-
            Non-empty list of SKU + quantity lines. The number of raw lines is
            limited to 100; the combined quantity across all lines is limited to
            100.
        toAddress:
          $ref: '#/components/schemas/CreateResendBySkuDestinationAddress'
          description: Destination address for the resend shipment.
        sellerReferenceNumber:
          type: string
          maxLength: 50
          description: >-
            Optional seller reference number. When provided, 1-50 characters
            with no invisible characters. Stored on the created resend shipment
            and echoed back in the response.
        description:
          type: string
          description: Optional free-text description for the resend order.
        remarks:
          type: string
          description: Optional free-text merchant remarks for the resend order.
        warehouseRemarks:
          type: string
          description: Optional free-text remarks addressed to the warehouse.
      required:
        - warehouseId
        - shipmentServiceType
        - itemList
        - toAddress
    CreateResendBySkuResponse:
      type: object
      description: >-
        Wraps `CreateResendBySkuReply` under `data`, alongside the standard
        `correlationId` and `meta` envelope.
      properties:
        data:
          $ref: '#/components/schemas/CreateResendBySkuReply'
          description: Create resend by SKU result.
    ApiResponse:
      type: object
      description: >-
        Universal response envelope. Successful responses include the business
        payload as additional top-level fields alongside `correlationId` and
        `meta`. Failed responses (auth errors, validation errors) only populate
        `correlationId` and `meta`, with `meta.errorCode` and `meta.error`
        describing the failure.
      properties:
        correlationId:
          type:
            - string
            - 'null'
          description: >-
            Unique correlation ID for tracing the request through Return Helper
            systems.
        meta:
          $ref: '#/components/schemas/ApiResponseMeta'
    CreateResendBySkuItem:
      type: object
      description: >-
        One requested SKU line. Duplicate SKUs (after trim and uppercase
        normalization) are combined before validation, so their quantities are
        summed.
      properties:
        sku:
          type: string
          maxLength: 32
          description: >-
            SKU to resend. After trim and uppercase normalization must match the
            SKU pattern (alphanumerics plus `#`, `-`, `_`; maximum 32
            characters). Matched against warehouse-scoped SKU inventory.
        quantity:
          type: integer
          description: Number of units of this SKU to resend. Must be greater than 0.
      required:
        - sku
        - quantity
    CreateResendBySkuDestinationAddress:
      type: object
      description: >-
        Destination address for the resend shipment. `addressType` is used only
        for label creation and is not persisted on the resend shipment.
      properties:
        contactName:
          type: string
          maxLength: 100
          description: Recipient contact name. Single line (no tab), 1-100 characters.
        street1:
          type: string
          maxLength: 100
          description: Address line 1. Single line (no tab), 1-100 characters.
        street2:
          type: string
          maxLength: 100
          description: Address line 2. Single line (no tab), 1-100 characters.
        street3:
          type: string
          maxLength: 100
          description: >-
            Address line 3. Optional. When provided, single line (no tab),
            maximum 100 characters.
        city:
          type: string
          maxLength: 50
          description: City. Single line (no tab), 1-50 characters.
        state:
          type: string
          maxLength: 50
          description: State / province. Single line (no tab), 1-50 characters.
        postalCode:
          type: string
          maxLength: 50
          description: >-
            Postal code. 1-50 characters, no leading whitespace. UK postal-code
            format is enforced when `country` is `gbr`.
        country:
          type: string
          description: >-
            Destination country as an ISO3 code (lowercase on the wire, e.g.
            `usa`, `gbr`). Must be a country code accepted by country
            validation.
        phone:
          type: string
          maxLength: 50
          description: >-
            Recipient phone. Single line, 1-50 characters, digits and `+`, `(`,
            `)` only.
        fax:
          type: string
          maxLength: 50
          description: >-
            Recipient fax. Optional. Same format rules as `phone`, maximum 50
            characters.
        email:
          type: string
          maxLength: 100
          description: >-
            Recipient email. Optional. When provided, a valid single-line email,
            maximum 100 characters.
        addressType:
          type: string
          maxLength: 50
          description: >-
            Address type used for label creation (e.g. `business`,
            `residential`). Single line, maximum 50 characters. Not persisted on
            the resend shipment.
      required:
        - contactName
        - street1
        - street2
        - city
        - state
        - postalCode
        - country
        - phone
        - addressType
    CreateResendBySkuReply:
      type: object
      description: >-
        Payload returned under `data` for a successful Create resend by SKU
        call.
      properties:
        resendId:
          type: integer
          format: int64
          description: Created resend identifier.
        resendNumber:
          type: string
          description: System-generated resend number.
        resendShipmentId:
          type: integer
          format: int64
          description: Created resend shipment identifier.
        sellerReferenceNumber:
          type:
            - string
            - 'null'
          description: >-
            Seller reference number supplied in the request, echoed back. `null`
            when none was provided.
        selectedReturnInventoryList:
          type: array
          items:
            $ref: '#/components/schemas/CreateResendBySkuSelectedInventoryItem'
          description: >-
            Flat list of the return inventory records the service allocated to
            this resend, one entry per selected unit.
    ApiResponseMeta:
      type: object
      description: >-
        Application-level metadata for every API response. Inspect `status` and
        `errorCode` to detect soft-error responses (validation failures arrive
        as HTTP 200 with `meta.status: 400`).
      properties:
        status:
          type: integer
          description: >-
            Application-level status code. For successful operations this
            mirrors the HTTP status (e.g. 200). For validation failures it
            reports the logical status (e.g. 400) even though the wire HTTP
            status is 200.
        data:
          type: object
          additionalProperties:
            type: string
          description: Reserved free-form metadata key/value pairs. Usually empty.
        errorCode:
          type:
            - string
            - 'null'
          description: >-
            Machine-readable error code (e.g. `VALIDATION_FAILED`). Non-null
            only when the operation failed.
        error:
          type: object
          additionalProperties: true
          description: >-
            Field-level or message-level error detail keyed by request property
            name. Empty object on success.
    CreateResendBySkuSelectedInventoryItem:
      type: object
      description: A return inventory record the service selected to satisfy the request.
      properties:
        returnInventoryId:
          type: integer
          format: int64
          description: Identifier of the selected return inventory record.
        rmaCode:
          type: string
          description: RMA code of the selected return inventory record.
        sku:
          type: string
          description: Normalized (trimmed, uppercased) SKU of the selected record.
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: x-rr-apikey
      description: Your API key
    ApiToken:
      type: apiKey
      in: header
      name: x-rr-apitoken
      description: Your API token — keep this private

````