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

# Decide what to do with an order returned by the carrier

> When a carrier cannot deliver an order and brings it back, Cubbo creates a return of type
`RETURNED_BY_CARRIER` in status `PENDING` and waits for a decision. Use this endpoint to take
that decision:

- `resend`: Cubbo duplicates the original order into a new order (same items, same shipping
  data, cash-on-delivery and document/pickup requirements carried over), assigns the units
  reserved by the return to it and ships it again. The return moves to `ORDERED` and the new
  order is returned in `created_order`. Answers 201.
- `cancel_forward`: the order is not resent. The reserved units are released back to
  available inventory and the return moves to `CANCELLED`. Answers 200.

Only a `PENDING` return of type `RETURNED_BY_CARRIER` can be decided; anything else answers
422 `RETURN_NOT_DECIDABLE`. Your API credentials need the permission to resolve returns.




## OpenAPI

````yaml /openapi.yaml post /returns/{return_id}/decision
openapi: 3.1.0
info:
  title: Cubbo Clients API
  version: '1.0'
  summary: >-
    Orders, inventory, replenishments, returns, shipping and webhooks for Cubbo
    fulfillment.
  description: >
    The Cubbo Clients API connects your store, ERP or marketplace with Cubbo's
    fulfillment network.

    All endpoints except `POST /auth/token` require a bearer token; see the
    Authentication guide.

    Request and response bodies are JSON. Errors are JSON objects with an
    `error` key.
  contact:
    name: Cubbo integrations
    email: integraciones@cubbo.com
servers:
  - url: https://api.cubbo.com/v1
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: Exchange client credentials for a bearer token.
  - name: Orders
    description: Create, update, hold, cancel and read sales orders.
  - name: Shipping labels
    description: Read the shipping labels generated for an order.
  - name: Inventory
    description: Products and stock per store.
  - name: Lots
    description: Lot-level inventory for products with expiration or batch tracking.
  - name: Reports
    description: Bulk reports for reconciliation.
  - name: Replenishments
    description: Inbound shipments to the warehouse.
  - name: Returns
    description: Returns and exchanges.
  - name: Stores
    description: Store provisioning and settings.
  - name: Shipping methods
    description: Available shipping methods, coverage and quotes.
  - name: Click and collect
    description: Pickup points and in-store pickup orders.
paths:
  /returns/{return_id}/decision:
    post:
      tags:
        - Returns
      summary: Decide what to do with an order returned by the carrier
      description: >
        When a carrier cannot deliver an order and brings it back, Cubbo creates
        a return of type

        `RETURNED_BY_CARRIER` in status `PENDING` and waits for a decision. Use
        this endpoint to take

        that decision:


        - `resend`: Cubbo duplicates the original order into a new order (same
        items, same shipping
          data, cash-on-delivery and document/pickup requirements carried over), assigns the units
          reserved by the return to it and ships it again. The return moves to `ORDERED` and the new
          order is returned in `created_order`. Answers 201.
        - `cancel_forward`: the order is not resent. The reserved units are
        released back to
          available inventory and the return moves to `CANCELLED`. Answers 200.

        Only a `PENDING` return of type `RETURNED_BY_CARRIER` can be decided;
        anything else answers

        422 `RETURN_NOT_DECIDABLE`. Your API credentials need the permission to
        resolve returns.
      operationId: decideReturn
      parameters:
        - name: return_id
          in: path
          required: true
          description: Numeric id of the return.
          schema:
            type: integer
          example: 98765
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReturnDecisionRequest'
            examples:
              resend:
                value:
                  decision: resend
              cancelForward:
                value:
                  decision: cancel_forward
      responses:
        '200':
          description: Decision `cancel_forward` applied; the return is cancelled.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReturnDecisionCancelForwardResult'
              example:
                decision: cancel_forward
                return_id: 98765
                return_status: CANCELLED
        '201':
          description: >-
            Decision `resend` applied; a new order was created from the returned
            one.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReturnDecisionResendResult'
              example:
                decision: resend
                return_id: 98765
                return_status: ORDERED
                created_order:
                  id: 445577
                  order_number: ORD-0001_RC
                  status: pending
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          description: No return with that id in your stores.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: no return found with return_id 98765
        '409':
          description: >-
            Another decision for the same return is still being processed (or
            Cubbo is resolving it internally).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReturnError'
              example:
                error: a decision for this return is already in progress
                code: DECISION_IN_FLIGHT
        '422':
          description: Validation or business error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReturnError'
              examples:
                invalidDecision:
                  value:
                    error: >-
                      Parameter decision must be within ["resend",
                      "cancel_forward"]
                    code: null
                missingDecision:
                  value:
                    error: Parameter decision is required
                    code: null
                notDecidable:
                  value:
                    error: >-
                      return 98765 is not a pending returned-by-carrier return
                      and cannot be decided
                    code: RETURN_NOT_DECIDABLE
                notCancelable:
                  summary: cancel_forward raced with a concurrent cancellation
                  value:
                    error: return 98765 is not pending and cannot be cancelled
                    code: RETURN_NOT_CANCELABLE
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - bearerAuth: []
components:
  schemas:
    ReturnDecisionRequest:
      type: object
      required:
        - decision
      properties:
        decision:
          type: string
          description: >-
            `resend` creates a new order from the returned one and ships it
            again; `cancel_forward` cancels the return and releases its reserved
            stock.
          enum:
            - resend
            - cancel_forward
          example: resend
    ReturnDecisionCancelForwardResult:
      type: object
      required:
        - decision
        - return_id
        - return_status
      properties:
        decision:
          type: string
          description: The applied decision.
          enum:
            - cancel_forward
          example: cancel_forward
        return_id:
          type: integer
          description: Id of the decided return.
          example: 98765
        return_status:
          $ref: '#/components/schemas/ReturnStatus'
    ReturnDecisionResendResult:
      type: object
      required:
        - decision
        - return_id
        - return_status
        - created_order
      properties:
        decision:
          type: string
          description: The applied decision.
          enum:
            - resend
          example: resend
        return_id:
          type: integer
          description: Id of the decided return.
          example: 98765
        return_status:
          $ref: '#/components/schemas/ReturnStatus'
        created_order:
          type: object
          description: >-
            The new order created from the returned one. Fetch it with the
            orders endpoints for full details.
          required:
            - id
            - order_number
            - status
          properties:
            id:
              type: integer
              description: Id of the new order.
              example: 445577
            order_number:
              type: string
              description: >-
                Order number of the new order; derived from the original order
                number with a return-by-carrier suffix.
              example: ORD-0001_RC
            status:
              type: string
              description: Initial status of the new order.
              example: pending
    Error:
      type: object
      description: Error body returned by every failed request.
      required:
        - error
      properties:
        error:
          type: string
          description: >-
            Human-readable description of the failure. For `401` responses it is
            always `Unauthorized`.
          example: Parameter store_id is required
        message:
          type: string
          description: >-
            Present on `401` responses only; the reason the request was
            rejected.
          example: invalid token
        code:
          type:
            - string
            - 'null'
          description: >-
            Stable machine-readable code, present on some order, return and
            replenishment errors.
          example: ORDER_ALREADY_EXISTS
        context:
          type:
            - object
            - 'null'
          description: >-
            Extra data about the failure when available, for example the id of
            the conflicting order.
          additionalProperties: true
          example:
            order_id: 987654
    ReturnError:
      type: object
      description: >-
        Error body of the create, cancel and decision endpoints, with a
        machine-readable `code`.
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable message.
          example: order already has an active return
        code:
          type:
            - string
            - 'null'
          description: Stable error code; null for parameter validation errors.
          example: RETURN_ALREADY_EXISTS
        context:
          type:
            - object
            - 'null'
          description: >-
            Extra details, when available (for example the offending `sku`).
            Only sent by `POST /returns`.
          example:
            sku: SKU-RED-M
    ReturnStatus:
      type: string
      description: >
        Lifecycle status of a return.

        - `PENDING`: created and waiting for a decision (review of a customer
        request, or decision on an order returned by the carrier).

        - `REQUESTED`: resolved; the customer has the return instructions and
        the goods are expected back.

        - `ORDERED`: resolved by creating a new (replacement or resend) order.

        - `CANCELLED`: cancelled before the goods came back; reserved stock was
        released.

        - `ARRIVED_AT_WAREHOUSE`: the package arrived at the warehouse and is
        waiting to be processed.

        - `AWAITING_INSPECTION`: the package was opened and is waiting for
        inspection of its contents.

        - `RECEIVED`: the goods were checked in and are being re-entered into
        inventory.

        - `REENTERED`: the goods were fully re-entered into inventory; the
        return is complete.

        - `UNSUCCESSFUL`: closed without receiving anything; every expected
        product was missing on reception.
      enum:
        - PENDING
        - REQUESTED
        - ORDERED
        - CANCELLED
        - ARRIVED_AT_WAREHOUSE
        - AWAITING_INSPECTION
        - RECEIVED
        - REENTERED
        - UNSUCCESSFUL
      example: PENDING
  responses:
    Unauthorized:
      description: >-
        Missing or invalid token, wrong credentials, or no access to the
        requested store.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            invalidToken:
              value:
                error: Unauthorized
                message: invalid token
            noHeader:
              value:
                error: Unauthorized
                message: no authorization header found
            storeNotAllowed:
              value:
                error: Unauthorized
                message: not allowed to show? this Store
    InternalServerError:
      description: >-
        Unexpected error. Retry with backoff; if it persists, send the timestamp
        to Cubbo support.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 'unexpected error, timestamp: 1760000000'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Token returned by `POST /auth/token`, sent as `Authorization: Bearer
        <token>`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.