> ## 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>

以**倉庫層級的 SKU 數量**（而非明確的退件庫存 ID）建立補寄。

請求以**原子方式**處理——要嘛每個請求單位都被配置且建立單一補寄，要嘛完全不建立且請求失敗。不會有部分補寄。

<h2 id="when-to-use-this-vs-create-resend-order">
  何時使用本端點，而非 Create resend order
</h2>

* 當您以 SKU 與數量追蹤庫存、且不想管理個別 `returnInventoryId` 值時，使用**以 SKU 建立 Resend**。
* 當您已握有想補寄的特定 `returnInventoryId` 值（例如從 `newInventoryCreated` webhook 快取而來）時，使用 [Create resend order](/zh-Hant/api-reference/resend/create-resend-order)。

<h2 id="prerequisites">
  前置條件
</h2>

* 您的帳戶已啟用 SKU 庫存模組（Enterprise）。
* 該倉庫中每個請求的 SKU 都有足夠、符合補寄資格的庫存。請先以 [搜尋 SKU 庫存](/zh-Hant/api-reference/skuinventory/search-sku-inventory)（`availableQuantity`）確認彙總量，但請注意通過彙總檢查並非保證——見下文。
* `shipmentServiceType` 是 **Shipment Service Type**（**不是** Return Service Type）。有效代碼請見 [取得 Warehouse 可用的 Shipment Service Types](/zh-Hant/api-reference/shipmentservicetype/get-available-shipment-service-types-for-warehouse)。

<h2 id="how-selection-works">
  挑選機制
</h2>

配置分三個階段，且只有最後一個階段具權威性：

1. **驗證。** 您的請求行會被正規化（SKU trim + 轉大寫），重複的 SKU 會被合併。驗證會依 `warehouseId` + 正規化後 SKU 檢查 `availableQuantity`。通過此檢查**僅**代表彙總量看起來足夠——**不會**保留或配置任何東西。
2. **挑選。** 系統查詢符合您 `warehouseId` 與正規化 SKU 且具補寄資格的實際退件庫存記錄，再依[挑貨策略](#pick-up-strategy)恰好挑出所請求的數量。若符合資格的記錄少於請求量，整筆請求會被拒絕。
3. **配置。** 在交易內，將被挑選的列加鎖並重新檢查；若有任何一列不再符合資格，交易回滾且請求失敗。否則所有被挑選的記錄會被推進至 resend / in-progress，並在同一交易內建立補寄。

<Warning>
  `SkuInventory.availableQuantity` 是**提前檢查，並非保留。** 多個並行請求可能同時通過相同的彙總檢查；只有成功鎖定並取得底層記錄的請求才會提交（commit）。其餘請求會以驗證錯誤失敗，並可重試。加鎖的配置始終是最終權威。
</Warning>

<h2 id="eligibility-rules">
  資格規則
</h2>

退件庫存記錄唯有在符合以下條件時才可被挑選：

* 符合請求的 `warehouseId` 與正規化後 SKU；
* `handlingStatusCode` = **pending**；
* 可轉換至 resend / in-progress；且
* **無待處理 VAS**，包含任何未完成的 VAS Split。

由於資格以狀態為基準，MySQL 符合資格的數量可能**低於**彙總的 `availableQuantity`（後者仍可能計入帶待處理 VAS 的記錄）。當發生此情況時，請求會以 fail-closed 方式失敗，而非補寄不符資格的項目。

<h2 id="pick-up-strategy">
  挑貨策略
</h2>

挑選預設採 **LIFO**：最新 `createOn` 優先，並以最大的退件庫存 ID 作為決勝依據。此策略置於工廠（factory）之後，未來可切換為 FIFO 而不需更動配置邏輯。

<h2 id="errors-and-retries">
  錯誤與重試
</h2>

* 驗證失敗會以 HTTP 200 搭配 `meta.status: 400` 回傳（標準的軟錯誤封套——見[錯誤處理](/zh-Hant/introduction#error-handling)）。
* 當某個 SKU 可用量不足時，會**整筆**拒絕請求。基於安全考量，錯誤**不會**揭露剩餘可用量。
* 當並行請求爭用相同庫存時，未能鎖定記錄的請求會被拒絕，並可重試。

<h2 id="related">
  相關
</h2>

* [搜尋 SKU 庫存](/zh-Hant/api-reference/skuinventory/search-sku-inventory) — 在請求前確認 `availableQuantity`。
* [Create resend order](/zh-Hant/api-reference/resend/create-resend-order) — 以明確的退件庫存 ID 補寄；亦涵蓋面單產生（自動 vs 手動服務類型）與取消截止時間，這些同樣適用於此處建立的補寄。
* [取消補寄訂單](/zh-Hant/api-reference/resend/cancel-resend-order) — 在倉庫出貨前中止。
* [Webhooks](/zh-Hant/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

````