> ## Documentation Index
> Fetch the complete documentation index at: https://api-doc.xmenu.it/llms.txt
> Use this file to discover all available pages before exploring further.

# Order preview

> Validates an order without creating it and returns the computed quote (total, delivery fee and applied coupons, including automatic ones). Accepts the same payload as order creation.

<Badge color="blue" icon="key">`write:orders`</Badge>


## OpenAPI

````yaml openapi-en.json POST /order/preview
openapi: 3.1.0
info:
  title: xMenu API
  description: xMenu Public API - REST endpoints and webhook notifications
  version: 1.0.0
servers:
  - url: https://app.xmenu.it/api
    description: xMenu API Production
security: []
paths:
  /order/preview:
    post:
      tags:
        - Order Insertion
      summary: Order preview
      description: >-
        Validates an order without creating it and returns the computed quote
        (total, delivery fee and applied coupons, including automatic ones).
        Accepts the same payload as order creation.
      operationId: orderPreview
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrderRequest'
      responses:
        '200':
          description: Order preview response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrderPreviewResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
      security:
        - clientId: []
          clientSecret: []
        - oauth2: []
components:
  schemas:
    OrderRequest:
      type: object
      required:
        - client
        - dmethod
        - payment_method
        - details
      properties:
        subrestaurant_uid:
          type: string
          description: Location identifier. Required for multi-location restaurants
        client:
          type: object
          required:
            - first_name
          properties:
            first_name:
              type: string
              description: Customer first name
            last_name:
              type: string
              description: Customer last name
            email:
              type: string
              description: Customer email
            phone:
              type: string
              description: Customer phone
        dmethod:
          type: string
          description: |-
            Delivery method:
            - `0` = pickup at location
            - `1` = home delivery
            - `0t` = at table
            - `20` = pickup at pickup point
            - `0e-{id}` = event (where {id} is the event ID)
            - `dcf-{id}` = custom method (where {id} is the method ID)
        language:
          type: string
          description: ISO 639-1 language code; defaults to restaurant settings
        pickup:
          type: object
          required:
            - date
          description: Pickup data. Required for `dmethod`=0
          properties:
            date:
              type: string
              format: date-time
              description: Desired pickup date and time
        delivery:
          type: object
          required:
            - date
            - address
          description: Delivery data. Required for `dmethod`=1
          properties:
            date:
              type: string
              format: date-time
              description: Desired delivery date and time
            address:
              type: object
              required:
                - place_id
              properties:
                place_id:
                  type: string
                  description: Address identifier from validation
                doorbell:
                  type: string
                  description: Doorbell
                floor:
                  type: string
                  description: Floor
        payment_method:
          type: string
          enum:
            - cash
            - invoice
            - external
          description: |-
            Payment method:
            - `cash` = cash
            - `invoice` = invoice
            - `external` = externally handled
        payment_method_sub:
          type: string
          description: Payment sub-method. Required if payment_method=cash
        details:
          type: array
          description: Order items (products with quantities/options)
          items:
            type: object
            required:
              - product
              - quantity
            properties:
              product:
                type: object
                required:
                  - uid
                properties:
                  uid:
                    type: string
                    description: Product ID
              quantity:
                type: integer
                description: Product quantity
              notes:
                type: string
                description: Item-specific notes
              options:
                type: array
                description: Selected customizations with values
                items:
                  type: object
                  required:
                    - uid
                    - values
                  properties:
                    uid:
                      type: string
                      description: Unique option identifier
                    values:
                      type: array
                      description: >-
                        Selected option values. For single-choice options,
                        contains one element; for multiple-choice, contains
                        selected items
                      items:
                        type: object
                        required:
                          - uid
                        properties:
                          uid:
                            type: string
                            description: Unique option value identifier
                          quantity:
                            type: integer
                            description: 'Option value quantity. Default: 1'
        coupon:
          type: object
          required:
            - code
          description: Coupon to apply to the order.
          properties:
            code:
              type: string
              description: Coupon code to apply.
        notes:
          type: string
          description: General order notes
        creator:
          type: string
          enum:
            - customer
            - restaurant
          description: >-
            Order origin:

            - `customer` = self-placed online order (default)

            - `restaurant` = phone order placed by the restaurant on behalf of
            the customer
    OrderPreviewResponse:
      type: object
      required:
        - success
      properties:
        success:
          type: boolean
          description: 'Operation result: `true` if the order is valid, `false` if failed'
        error:
          type: string
          description: >-
            Error code if validation failed (same as order creation). Possible
            values:

            - `PRODUCT_NOT_FOUND` = product not found

            - `PRODUCT_NOT_AVAILABLE` = product unavailable

            - `OPTION_NOT_FOUND` = option not found

            - `OPTION_VALUE_NOT_FOUND` = option value not found

            - `INVALID_ADDRESS` = invalid address or out of zone

            - `COUPON_ERROR` = coupon application error

            - `SUBRESTAURANT_NOT_FOUND` = location not found


            See [Error codes](/docs/en/overview/error-codes) for general error
            codes that may occur.
        message:
          type: string
          description: Human-readable error description if validation failed
        order:
          type: object
          description: >-
            Computed order quote (present only if success = true). No order is
            created.
          required:
            - total
          properties:
            total:
              type: number
              format: double
              description: Estimated order total calculated by the system
            delivery_fee:
              type: number
              format: double
              description: Delivery cost
            pickup_date:
              type: string
              format: date-time
              description: Pickup date and time at location
            delivery_date:
              type: string
              format: date-time
              description: Home delivery date and time
            coupon:
              $ref: '#/components/schemas/Coupon'
              description: Applied coupon (automatic or manual)
    Coupon:
      type: object
      description: Applied discount coupon details
      required:
        - code
        - description
        - discount
        - auto
      properties:
        code:
          type: string
          description: Coupon code
        description:
          type: string
          description: Coupon description
        discount:
          type: number
          description: Discount amount
        auto:
          type: boolean
          description: Whether the coupon was applied automatically
  responses:
    Unauthorized:
      description: Authentication failed.
      content:
        application/json:
          schema:
            oneOf:
              - type: object
                description: >-
                  Standard error format (when using API Key or Client ID/Secret
                  authentication)
                required:
                  - success
                  - error
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                    description: Always false for errors
                  error:
                    type: string
                    enum:
                      - RESTAURANT_NOT_FOUND
                      - INVALID_KEY
                      - INVALID_AUTH
                    description: Error code
                  message:
                    type: string
                    description: Human-readable error description
              - type: object
                description: OAuth error format (when using Bearer token authentication)
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - invalid_token
                      - invalid_request
                    description: OAuth error code (RFC 6749)
                  error_description:
                    type: string
                    description: Human-readable error description
          examples:
            standard:
              summary: Standard error format (API Key / Client ID+Secret)
              value:
                success: false
                error: INVALID_KEY
                message: The provided API key is not valid
            oauth:
              summary: OAuth error format (Bearer token)
              value:
                error: invalid_token
                error_description: Access token is invalid or expired
    Forbidden:
      description: Authorization failed - insufficient permissions or access denied.
      content:
        application/json:
          schema:
            oneOf:
              - type: object
                description: >-
                  Standard error format (when using API Key or Client ID/Secret
                  authentication)
                required:
                  - success
                  - error
                properties:
                  success:
                    type: boolean
                    enum:
                      - false
                    description: Always false for errors
                  error:
                    type: string
                    enum:
                      - API_DISABLED
                      - INSUFFICIENT_SCOPE
                      - UNAUTHORIZED
                    description: Error code
                  message:
                    type: string
                    description: Human-readable error description
              - type: object
                description: OAuth error format (when using Bearer token authentication)
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - insufficient_scope
                      - invalid_request
                    description: OAuth error code (RFC 6749)
                  error_description:
                    type: string
                    description: Human-readable error description
          examples:
            standard:
              summary: Standard error format (API Key / Client ID+Secret)
              value:
                success: false
                error: API_DISABLED
                message: API access is not enabled for the restaurant
            oauth:
              summary: OAuth error format (Bearer token)
              value:
                error: insufficient_scope
                error_description: 'Missing required permissions: write:orders'
  securitySchemes:
    clientId:
      type: apiKey
      in: header
      name: X-Client-Id
      description: >-
        Client ID for API Client authentication (must be used together with
        Client Secret)
    clientSecret:
      type: apiKey
      in: header
      name: X-Client-Secret
      description: >-
        Client Secret for API Client authentication (must be used together with
        Client ID)
    oauth2:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: https://app.xmenu.it/oauth/token
          scopes: {}
      description: >-
        OAuth 2.0 authentication using client credentials flow. The access token
        must be included in the Authorization header as a Bearer token.

````