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

# Preview order

> Preview the order as if the given rewards were redeemed. If a wallet reward is restricted to stores, channels, or products, the preview only applies it when the order contains a matching store_id, channel_id, or product sku. Rewards with null e-commerce scope have no e-commerce restriction.



## OpenAPI

````yaml PUT /events/redeem/preview
openapi: 3.0.1
info:
  title: Masivo's REST API
  description: Learn how to use Masivo's REST API
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://app.masivo.ai/api/storefront/v1
security:
  - bearerAuth: []
paths:
  /events/redeem/preview:
    put:
      description: >-
        Preview the order as if the given rewards were redeemed. If a wallet
        reward is restricted to stores, channels, or products, the preview only
        applies it when the order contains a matching store_id, channel_id, or
        product sku. Rewards with null e-commerce scope have no e-commerce
        restriction.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - customer_id
                - brand_id
                - order
              properties:
                platform:
                  type: string
                  description: Platform name where the event originated
                  nullable: true
                customer_id:
                  type: string
                  description: The customer unique identifier in your system
                brand_id:
                  type: string
                  nullable: true
                  description: The brand id of the order
                order:
                  $ref: '#/components/schemas/OrderPreview'
                  description: The order to apply the rewards
            example: {}
        required: true
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      customer_id:
                        type: string
                        description: The customer unique identifier in your system
                      brand_id:
                        type: string
                        nullable: true
                        description: The brand id of the order
                      order:
                        $ref: '#/components/schemas/OrderPreview'
                        description: The order with the rewards applied
                      redemption_steps:
                        type: array
                        description: >-
                          Chronological changes produced by each redemption.
                          Existing order fields keep their final values
                          unchanged.
                        items:
                          $ref: '#/components/schemas/RedemptionStep'
        '422':
          description: Insufficient funds
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    OrderPreview:
      allOf:
        - $ref: '#/components/schemas/Order'
        - type: object
          properties:
            products:
              type: array
              items:
                $ref: '#/components/schemas/ProductPreview'
            shipping:
              $ref: '#/components/schemas/ShippingPreview'
            redemptions_result:
              $ref: '#/components/schemas/RedemptionsResult'
              description: The result of the redemptions over the order
    RedemptionStep:
      type: object
      description: One reward application and the financial transition it produced
      required:
        - reward_id
        - reward_amount
        - target
        - target_id
        - action
        - discount_value
        - before
        - after
      properties:
        reward_id:
          type: string
          format: uuid
          description: The redeemed reward id
        reward_amount:
          type: number
          description: The redeemed reward amount
        target:
          type: string
          enum:
            - order
            - shipping
            - product
          description: >-
            Where the reward was requested; use this to map order/product and
            delivery discount codes
        target_id:
          type: string
          nullable: true
          description: Product SKU when target is product; otherwise null
        action:
          type: string
          enum:
            - UPDATE
            - READ
            - CREATE
            - REMOVE
          description: The action produced by this redemption
        discount_value:
          type: number
          description: >-
            This redemption's contribution to the order discount; zero when it
            failed or was fully capped
        before:
          $ref: '#/components/schemas/RedemptionStepState'
          description: Order-level financial state before this redemption
        after:
          $ref: '#/components/schemas/RedemptionStepState'
          description: Order-level financial state after this redemption
        target_before:
          $ref: '#/components/schemas/RedemptionStepState'
          description: >-
            Product or shipping state before this redemption; omitted when
            target is order
        target_after:
          $ref: '#/components/schemas/RedemptionStepState'
          description: >-
            Product or shipping state after this redemption; omitted when target
            is order
        error:
          type: string
          description: The error when this redemption was not applied
    Error:
      required:
        - error
        - details
      type: object
      properties:
        error:
          type: string
        details:
          type: string
    Order:
      type: object
      required:
        - purchase_id
        - value
        - products
        - payment_method
      properties:
        purchase_id:
          type: string
          description: The id of a placed order in your system
        channel_id:
          type: string
          description: >-
            The channel unique identifier in your system. Used to match campaign
            and reward e-commerce channel restrictions.
        store_id:
          type: string
          description: >-
            The store unique identifier in your system. Used to match campaign
            and reward e-commerce store restrictions.
        value:
          type: number
          description: The order total or subtotal
          example: 20.95
        discounted_value:
          type: number
          description: The order total or subtotal after discounts
          example: 10.95
        products:
          type: array
          description: >-
            Products in the order. Product sku values are used to match campaign
            and reward e-commerce product restrictions.
          minimum: 1
          items:
            $ref: '#/components/schemas/OrderProduct'
        shipping:
          $ref: '#/components/schemas/Shipping'
          description: The shipping information of the order
        payment_method:
          type: string
          description: The payment method used in the order
          enum:
            - CREDIT
            - DEBIT
            - CASH
            - BANK_TRANSFER
            - OTHER
        redeem:
          type: array
          description: The rewards to redeem in the order
          items:
            $ref: '#/components/schemas/RedemptionReward'
        metadata:
          type: object
          description: The metadata of the order
    ProductPreview:
      allOf:
        - $ref: '#/components/schemas/OrderProduct'
        - type: object
          properties:
            redemptions_result:
              $ref: '#/components/schemas/RedemptionsResult'
              description: The result of the redemptions over the product
    ShippingPreview:
      allOf:
        - $ref: '#/components/schemas/Shipping'
        - type: object
          properties:
            redemptions_result:
              $ref: '#/components/schemas/RedemptionsResult'
              description: The result of the redemptions over the shipping
    RedemptionsResult:
      type: object
      description: The final result of all redemptions over the order, shipping & products
      properties:
        redeemed:
          type: array
          description: The rewards that have been redeemed
          items:
            $ref: '#/components/schemas/RedeemedReward'
        amount:
          type: number
          description: The amount of the reward redeemed
          format: int2
        discount_value:
          type: number
          description: The total discount reduced from the original value
        discount_percent:
          type: number
          nullable: true
          description: The percentage of the total discount reduced from the original value
          minimum: 0
          maximum: 1
        value:
          type: number
          nullable: true
          description: The updated value of the item after the discount
        action:
          type: string
          description: >-
            The action to perform over this item in your order. UPDATE to update
            the item. READ to keep the item. CREATE to create a new item. REMOVE
            to remove the item
          enum:
            - UPDATE
            - READ
            - CREATE
            - REMOVE
    RedemptionStepState:
      type: object
      description: Financial state at one point in the redemption sequence
      required:
        - value
        - amount
        - discount_value
        - discount_percent
      properties:
        value:
          type: number
          nullable: true
          description: Current value after discounts applied up to this point
        amount:
          type: number
          description: Current item amount
        discount_value:
          type: number
          description: Discount accumulated up to this point
        discount_percent:
          type: number
          nullable: true
          minimum: 0
          maximum: 1
          description: >-
            Cumulative discount percentage for this state; order states include
            the estimated value of product rewards
    OrderProduct:
      type: object
      required:
        - sku
        - amount
        - value
      properties:
        sku:
          type: string
          description: >-
            The product sku. Used to match campaign and reward e-commerce
            product restrictions.
        amount:
          type: number
          description: The quantity of the product
        value:
          type: number
          description: The total or subtotal of the product
        discounted_value:
          type: number
          description: The total or subtotal of the product after discounts
        redeem:
          type: array
          description: The rewards to redeem in the product
          items:
            $ref: '#/components/schemas/RedemptionReward'
        tags:
          type: object
          description: Include your conditions event tags here
        metadata:
          type: object
          description: Include any additional info here
    Shipping:
      type: object
      properties:
        value:
          type: number
          description: The shipping cost
          example: 3.25
        discounted_value:
          type: number
          description: The shipping cost after discounts
          example: 2.25
        redeem:
          type: array
          description: The rewards to redeem in the shipping
          items:
            $ref: '#/components/schemas/RedemptionReward'
        tags:
          type: object
          description: Include your conditions event tags here
        metadata:
          type: object
          description: Include any additional info here
    RedemptionReward:
      type: object
      properties:
        id:
          type: string
          description: The reward id to redeem
          format: uuid
        amount:
          type: number
          description: The amount of the reward to redeem. (Per product if applicable)
          example: 1
    RedeemedReward:
      allOf:
        - $ref: '#/components/schemas/RedemptionReward'
        - type: object
          properties:
            reward:
              $ref: '#/components/schemas/Reward'
              nullable: true
            error:
              type: string
              description: The error message if the reward was not redeemed
    Reward:
      allOf:
        - type: object
          properties:
            id:
              type: string
              description: The reward internal unique identifier
              format: uuid
        - $ref: '#/components/schemas/RewardInsert'
    RewardInsert:
      type: object
      properties:
        brand_id:
          type: string
          description: The brand id of the reward, null if is a global reward
          nullable: true
        platforms:
          type: array
          description: Platforms where this reward applies
          items:
            type: string
          nullable: true
        stores:
          type: array
          description: >-
            Store ids this reward is restricted to. null means no store
            restriction; a non-empty array restricts the reward to those stores;
            [] is an explicit empty restriction and matches no stores.
          items:
            type: string
          nullable: true
        channels:
          type: array
          description: >-
            Channel ids this reward is restricted to. null means no channel
            restriction; a non-empty array restricts the reward to those
            channels; [] is an explicit empty restriction and matches no
            channels.
          items:
            type: string
          nullable: true
        products:
          type: array
          description: >-
            Product ids this reward is restricted to. null means no product
            restriction; a non-empty array restricts the reward to those
            products; [] is an explicit empty restriction and matches no
            products.
          items:
            type: string
          nullable: true
        name:
          type: string
          description: The name of the reward
        description:
          type: string
          description: The description of the reward
        type:
          type: string
          description: The type of the reward
          enum:
            - POINTS
            - DISCOUNT
            - GIFT_CARD
            - PRODUCT
            - CUSTOM
        conditions:
          $ref: '#/components/schemas/AlternativeCondition'
        attributes:
          description: The attributes of the reward
          oneOf:
            - type: object
              description: The attributes of rewards of type POINTS
              properties:
                conversion_factor:
                  type: number
                  description: How much 1 point is worth in your currency
                  example: 0.1
            - description: The attributes of rewards of type DISCOUNT
              type: object
              properties:
                discount_value:
                  type: number
                  description: The discount value
                  example: 10
                discount_type:
                  type: string
                  description: The type of discount
                  enum:
                    - fixed
                    - percentage
                type:
                  type: string
                  description: The discount will be applied to
                  enum:
                    - shipping
                    - order
                    - product
    AlternativeCondition:
      type: array
      description: OR conditions
      items:
        $ref: '#/components/schemas/CompoundCondition'
    CompoundCondition:
      type: array
      description: AND conditions
      items:
        $ref: '#/components/schemas/Condition'
    Condition:
      type: object
      properties:
        type:
          type: string
          description: The type of the condition
          example: Order Value
        operator:
          type: string
          description: The operator to compare the attribute
          example: grater than
        primitive:
          type: string
          description: The primitive of the value to compare
          enum:
            - string
            - number
            - currency
            - boolean
            - absolute date
            - relative date
            - recurring date
        value:
          oneOf:
            - type: number
              example: 9.95
            - type: string
            - type: boolean
          description: The value to compare
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````