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

# Apply Discount

> Apply a discount code to a cart. Replaces any prior code on the
same cart (one code per cart). Computes pro-rata line
allocations and writes a `discount_redemptions` row pinned to
the cart_id.



## OpenAPI

````yaml /api-reference/openapi.json post /api/storefront/cart/{cart_id}/discounts
openapi: 3.1.0
info:
  title: Agentic Commerce API
  description: |2-

        Agentic Commerce API - E-commerce Backend

        ## APIs

        ### Dashboard API (`/api/dashboard`)
        Authenticated endpoints for merchant management:
        - Products, Variants, Options
        - Inventory management
        - Orders and fulfillment
        - Customers
        - Collections

        ### Storefront API (`/api/storefront`)
        Public endpoints for client websites:
        - Product catalog
        - Collections
        - Cart management
        - Checkout

        ### Sync API (`/api/sync`)
        Integration endpoints for zunkiree-search:
        - Product sync
        - Availability checks
        - Order creation from AI widget
        
  version: 1.0.0
servers: []
security: []
paths:
  /api/storefront/cart/{cart_id}/discounts:
    post:
      tags:
        - Storefront
        - Cart
      summary: Apply Discount
      description: |-
        Apply a discount code to a cart. Replaces any prior code on the
        same cart (one code per cart). Computes pro-rata line
        allocations and writes a `discount_redemptions` row pinned to
        the cart_id.
      operationId: apply_discount_api_storefront_cart__cart_id__discounts_post
      parameters:
        - name: cart_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
            title: Cart Id
        - name: X-Site-ID
          in: header
          required: true
          schema:
            type: string
            title: X-Site-Id
        - name: X-Stella-Token
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Stella-Token
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CartDiscountApplyRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CartDiscountResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    CartDiscountApplyRequest:
      properties:
        code:
          type: string
          maxLength: 64
          minLength: 1
          title: Code
      type: object
      required:
        - code
      title: CartDiscountApplyRequest
    CartDiscountResponse:
      properties:
        code:
          type: string
          title: Code
        kind:
          type: string
          title: Kind
        amount_off:
          type: string
          pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Amount Off
        currency:
          type: string
          title: Currency
        allocations:
          items:
            $ref: '#/components/schemas/CartDiscountAllocation'
          type: array
          title: Allocations
      type: object
      required:
        - code
        - kind
        - amount_off
        - currency
        - allocations
      title: CartDiscountResponse
      description: Returned after a successful apply.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    CartDiscountAllocation:
      properties:
        line_item_id:
          type: string
          format: uuid
          title: Line Item Id
        amount_off:
          type: string
          pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Amount Off
      type: object
      required:
        - line_item_id
        - amount_off
      title: CartDiscountAllocation
      description: Per-line discount distribution after apply.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````