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

# Cancel order

> Request cancellation of an order.

Order cancellations are subject to each merchant's cancellation policy.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/checkout-intents/openapi.documented.yml post /api/v1/orders/{id}/cancel
openapi: 3.0.0
info:
  title: Universal Checkout API
  version: 1.0.5
  description: >-
    Turn any product URL into a completed checkout. Instantly retrieve price,
    tax, and shipping for any product, and let users buy without ever leaving
    your native AI experience.


    View the [Rye API docs](https://docs.rye.com).
  termsOfService: https://rye.com/terms-of-service
  license:
    name: UNLICENSED
  contact:
    name: Rye
    email: dev@rye.com
    url: https://docs.rye.com
servers:
  - url: https://staging.api.rye.com
security: []
paths:
  /api/v1/orders/{id}/cancel:
    post:
      tags:
        - Orders
      summary: Cancel order
      description: |-
        Request cancellation of an order.

        Order cancellations are subject to each merchant's cancellation policy.
      operationId: CancelOrder
      parameters:
        - description: The order id
          in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        description: The cancellation reason (code + optional note)
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderCancelParams'
              description: ''
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Cancellation'
        '401':
          description: Authentication Failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthenticationError'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundError'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancellationNotApplicableError'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidateError'
      security:
        - bearerAuth:
            - checkout_intents:write
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import CheckoutIntents from 'checkout-intents';

            const client = new CheckoutIntents({
              apiKey: process.env['CHECKOUT_INTENTS_API_KEY'], // This is the default and can be omitted
            });

            const cancellation = await client.orders.cancel('id', {
              reason: { code: 'requested_by_customer' },
            });

            console.log(cancellation);
        - lang: Python
          source: |-
            import os
            from checkout_intents import CheckoutIntents

            client = CheckoutIntents(
                api_key=os.environ.get("CHECKOUT_INTENTS_API_KEY"),  # This is the default and can be omitted
            )
            cancellation = client.orders.cancel(
                id="id",
                reason={
                    "code": "requested_by_customer"
                },
            )
            print(cancellation)
        - lang: Java
          source: |-
            package com.rye.example;

            import com.rye.client.CheckoutIntentsClient;
            import com.rye.client.okhttp.CheckoutIntentsOkHttpClient;
            import com.rye.models.orders.Cancellation;
            import com.rye.models.orders.OrderCancelParams;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    CheckoutIntentsClient client = CheckoutIntentsOkHttpClient.fromEnv();

                    OrderCancelParams params = OrderCancelParams.builder()
                        .id("id")
                        .reason(OrderCancelParams.Reason.builder()
                            .code(OrderCancelParams.Reason.Code.REQUESTED_BY_CUSTOMER)
                            .build())
                        .build();
                    Cancellation cancellation = client.orders().cancel(params);
                }
            }
        - lang: cURL
          source: |-
            curl https://staging.api.rye.com/api/v1/orders/$ID/cancel \
                -H 'Content-Type: application/json' \
                -H "Authorization: Bearer $CHECKOUT_INTENTS_API_KEY" \
                -d '{
                      "reason": {
                        "code": "requested_by_customer"
                      }
                    }'
components:
  schemas:
    OrderCancelParams:
      properties:
        reason:
          $ref: '#/components/schemas/CancellationReason'
      required:
        - reason
      type: object
      description: >-
        Body for `POST /orders/{id}/cancel`. The order id comes from the URL, so
        the

        caller only supplies the cancellation reason (code + optional note).
    Cancellation:
      anyOf:
        - $ref: '#/components/schemas/RequestedCancellation'
        - $ref: '#/components/schemas/CompletedCancellation'
        - $ref: '#/components/schemas/DeniedCancellation'
    AuthenticationError:
      properties:
        name:
          type: string
        message:
          type: string
        stack:
          type: string
      required:
        - name
        - message
      type: object
      additionalProperties: false
    NotFoundError:
      properties:
        name:
          type: string
        message:
          type: string
        stack:
          type: string
      required:
        - name
        - message
      type: object
      additionalProperties: false
    CancellationNotApplicableError:
      description: >-
        The order cannot be programmatically cancelled — the store has no active

        integration, or the store's cancellation policy disallows it (disabled,

        outside the allowed window, already cancelled/fulfilled, over the value

        limit). Surfaced as a 409 carrying a machine-readable `code`; no
        cancellation

        record is written.
      properties:
        name:
          type: string
        message:
          type: string
        stack:
          type: string
        code:
          $ref: '#/components/schemas/CancellationNotApplicableCode'
      required:
        - name
        - message
        - code
      type: object
      additionalProperties: false
    ValidateError:
      properties:
        name:
          type: string
        message:
          type: string
        stack:
          type: string
        status:
          type: number
          format: double
        fields:
          $ref: '#/components/schemas/FieldErrors'
      required:
        - name
        - message
        - status
        - fields
      type: object
      additionalProperties: false
    CancellationReason:
      properties:
        message:
          type: string
          description: >-
            Optional free-text note explaining the cancellation, forwarded to
            the

            merchant when possible.
          maxLength: 256
        code:
          $ref: '#/components/schemas/CancellationReasonCode'
      required:
        - code
      type: object
    RequestedCancellation:
      allOf:
        - $ref: '#/components/schemas/BaseCancellation'
        - properties:
            state:
              type: string
              enum:
                - requested
              nullable: false
          required:
            - state
          type: object
    CompletedCancellation:
      allOf:
        - $ref: '#/components/schemas/BaseCancellation'
        - properties:
            state:
              type: string
              enum:
                - completed
              nullable: false
          required:
            - state
          type: object
    DeniedCancellation:
      allOf:
        - $ref: '#/components/schemas/BaseCancellation'
        - properties:
            denialReason:
              $ref: '#/components/schemas/CancellationDenialReason'
            state:
              type: string
              enum:
                - denied
              nullable: false
          required:
            - denialReason
            - state
          type: object
    CancellationNotApplicableCode:
      anyOf:
        - $ref: '#/components/schemas/CancellationRejectionCode'
        - type: string
          enum:
            - store_not_integrated
      description: >-
        Why a programmatic cancellation was rejected. `store_not_integrated` is
        our

        own pre-policy gate (not a Shopify store, or no active integration); the

        remaining codes come straight from the store cancellation policy
        evaluation

        in `@rye-com/rye-data-layer` (disabled, window expired, already

        cancelled/fulfilled, order value above limit).
    FieldErrors:
      properties: {}
      type: object
      additionalProperties:
        properties:
          value: {}
          message:
            type: string
        required:
          - message
        type: object
    CancellationReasonCode:
      type: string
      enum:
        - requested_by_customer
        - fraud
        - inventory
        - payment_issue
        - staff_error
        - other
    BaseCancellation:
      properties:
        reason:
          $ref: '#/components/schemas/CancellationReason'
        marketplaceOrderId:
          type: string
        checkoutIntentId:
          type: string
        createdAt:
          type: string
          format: date-time
        id:
          type: string
      required:
        - reason
        - marketplaceOrderId
        - checkoutIntentId
        - createdAt
        - id
      type: object
    CancellationDenialReason:
      properties:
        code:
          $ref: '#/components/schemas/CancellationDenialReasonCode'
        message:
          type: string
      required:
        - code
        - message
      type: object
    CancellationRejectionCode:
      $ref: '#/components/schemas/EnumValues_typeofCancellationRejectionCode_'
      description: >-
        Reason code for why automatic cancellation is not available/allowed for
        an order.


        Naming convention — `<subject>_<state>`, two namespaces:
          - `cancellation_*` — about the cancellation policy/feature itself.
          - `order_*`        — about the order's own state or attributes.
    CancellationDenialReasonCode:
      type: string
      enum:
        - other
        - already_shipped
        - non_cancellable_item
        - cancellation_window_expired
    EnumValues_typeofCancellationRejectionCode_:
      type: string
      enum:
        - cancellation_window_expired
        - cancellation_disabled
        - order_already_cancelled
        - order_already_fulfilled
        - order_value_above_limit
      description: The value-union of a {@link stringEnum} — e.g. `'red' | 'blue'`.
  securitySchemes:
    bearerAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Rye API key

````