> ## 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.

# Create Order From Ai

> Create an order from AI widget purchase.

This endpoint is called by zunkiree-search when a customer
completes a purchase through the AI chat widget.

The order will:
- Validate inventory availability
- Decrement stock
- Create customer if not exists
- Return order confirmation



## OpenAPI

````yaml /api-reference/openapi.json post /api/sync/orders
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/sync/orders:
    post:
      tags:
        - Sync
        - Sync Orders
      summary: Create Order From Ai
      description: |-
        Create an order from AI widget purchase.

        This endpoint is called by zunkiree-search when a customer
        completes a purchase through the AI chat widget.

        The order will:
        - Validate inventory availability
        - Decrement stock
        - Create customer if not exists
        - Return order confirmation
      operationId: create_order_from_ai_api_sync_orders_post
      parameters:
        - name: X-Sync-Secret
          in: header
          required: true
          schema:
            type: string
            title: X-Sync-Secret
        - name: X-Site-ID
          in: header
          required: true
          schema:
            type: string
            title: X-Site-Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SyncOrderCreate'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SyncOrderResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    SyncOrderCreate:
      properties:
        email:
          anyOf:
            - type: string
              format: email
            - type: 'null'
          title: Email
        phone:
          anyOf:
            - type: string
            - type: 'null'
          title: Phone
        line_items:
          items:
            $ref: '#/components/schemas/SyncOrderLineItem'
          type: array
          title: Line Items
        shipping_address:
          $ref: '#/components/schemas/AddressSchema'
        billing_address:
          anyOf:
            - $ref: '#/components/schemas/AddressSchema'
            - type: 'null'
        payment_method:
          type: string
          title: Payment Method
        payment_intent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Payment Intent Id
        note:
          anyOf:
            - type: string
            - type: 'null'
          title: Note
        subtotal:
          anyOf:
            - type: number
            - type: 'null'
          title: Subtotal
        total:
          anyOf:
            - type: number
            - type: 'null'
          title: Total
        currency:
          anyOf:
            - type: string
            - type: 'null'
          title: Currency
        source:
          type: string
          title: Source
          default: web
        external_id:
          anyOf:
            - type: string
            - type: 'null'
          title: External Id
        first_name:
          anyOf:
            - type: string
            - type: 'null'
          title: First Name
        last_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Last Name
        ig_username:
          anyOf:
            - type: string
            - type: 'null'
          title: Ig Username
      type: object
      required:
        - line_items
        - shipping_address
        - payment_method
      title: SyncOrderCreate
      description: Schema for creating order from AI widget.
    SyncOrderResponse:
      properties:
        id:
          type: string
          format: uuid
          title: Id
        order_number:
          type: string
          title: Order Number
        email:
          anyOf:
            - type: string
            - type: 'null'
          title: Email
        total:
          type: string
          pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Total
        currency:
          type: string
          title: Currency
        status:
          type: string
          title: Status
        payment_status:
          type: string
          title: Payment Status
        created_at:
          type: string
          format: date-time
          title: Created At
      type: object
      required:
        - id
        - order_number
        - total
        - currency
        - status
        - payment_status
        - created_at
      title: SyncOrderResponse
      description: Response for order created from AI.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SyncOrderLineItem:
      properties:
        variant_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Variant Id
        product_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Product Id
        size:
          anyOf:
            - type: string
            - type: 'null'
          title: Size
        color:
          anyOf:
            - type: string
            - type: 'null'
          title: Color
        quantity:
          type: integer
          title: Quantity
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        price:
          anyOf:
            - type: number
            - type: 'null'
          title: Price
        image_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Image Url
      type: object
      required:
        - quantity
      title: SyncOrderLineItem
      description: >-
        Line item for order from AI. Accepts variant_id directly, or product_id
        + size/color for variant resolution.

        Falls back to name + price when variant can't be resolved.
    AddressSchema:
      properties:
        first_name:
          anyOf:
            - type: string
            - type: 'null'
          title: First Name
        last_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Last Name
        company:
          anyOf:
            - type: string
            - type: 'null'
          title: Company
        address1:
          anyOf:
            - type: string
            - type: 'null'
          title: Address1
        address2:
          anyOf:
            - type: string
            - type: 'null'
          title: Address2
        city:
          anyOf:
            - type: string
            - type: 'null'
          title: City
        state:
          anyOf:
            - type: string
            - type: 'null'
          title: State
        postal_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Postal Code
        country:
          anyOf:
            - type: string
            - type: 'null'
          title: Country
        phone:
          anyOf:
            - type: string
            - type: 'null'
          title: Phone
      type: object
      title: AddressSchema
      description: >-
        Schema for address. Fields are optional to support simpler address
        formats from AI widget.
    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

````