> ## 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-Hans/api-reference/resend/create-resend-order)。

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

* 您的账户已启用 SKU 库存模块（Enterprise）。
* 该仓库中每个请求的 SKU 都有足够、符合补寄资格的库存。请先以 [搜索 SKU 库存](/zh-Hans/api-reference/skuinventory/search-sku-inventory)（`availableQuantity`）确认汇总量，但请注意通过汇总检查并非保证——见下文。
* `shipmentServiceType` 是 **Shipment Service Type**（**不是** Return Service Type）。有效代码请见 [获取 Warehouse 可用的 Shipment Service Types](/zh-Hans/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-Hans/introduction#error-handling)）。
* 当某个 SKU 可用量不足时，会**整笔**拒绝请求。基于安全考量，错误**不会**披露剩余可用量。
* 当并发请求争用相同库存时，未能锁定记录的请求会被拒绝，并可重试。

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

* [搜索 SKU 库存](/zh-Hans/api-reference/skuinventory/search-sku-inventory) — 在请求前确认 `availableQuantity`。
* [Create resend order](/zh-Hans/api-reference/resend/create-resend-order) — 以明确的退件库存 ID 补寄；亦涵盖面单生成（自动 vs 手动服务类型）与取消截止时间，这些同样适用于此处创建的补寄。
* [取消补寄订单](/zh-Hans/api-reference/resend/cancel-resend-order) — 在仓库发货前中止。
* [Webhooks](/zh-Hans/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

````