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

# Create a variant

> Creates a new variant for a product. Supports nested prices and stock items.

Option types and values are auto-created if they don't exist.
Prices are upserted by currency. Stock items are upserted by stock location.


**Required scope:** `write_products` (for API-key authentication).



## OpenAPI

````yaml /api-reference/admin.yaml post /api/v3/admin/products/{product_id}/variants
openapi: 3.0.3
info:
  title: Admin API
  contact:
    name: Spree Commerce
    url: https://spreecommerce.org
    email: hello@spreecommerce.org
  description: >
    Spree Admin API v3 - Administrative API for managing products, orders, and
    store settings.


    ## Authentication


    The Admin API requires a secret API key passed in the `x-spree-api-key`
    header.

    Secret API keys can be generated in the Spree admin dashboard.


    ## Response Format


    All responses are JSON. List endpoints return paginated responses with
    `data` and `meta` keys.

    Single resource endpoints return a flat JSON object.


    ## Resource IDs


    Every resource is identified by an opaque string ID (e.g. `prod_86Rf07xd4z`,

    `variant_k5nR8xLq`, `or_UkLWZg9DAJ`). Use these IDs everywhere — URL paths,

    request bodies, and Ransack filters all accept them directly.


    ## Error Handling


    Errors return a consistent format:

    ```json

    {
      "error": {
        "code": "validation_error",
        "message": "Validation failed",
        "details": { "name": ["can't be blank"] }
      }
    }

    ```
  version: v3
servers:
  - url: http://{defaultHost}
    variables:
      defaultHost:
        default: localhost:3000
security: []
tags:
  - name: Authentication
    description: Admin user login, logout, token refresh, and current user profile
  - name: Allowed Origins
    description: CORS allowlist for storefront and admin client origins
  - name: API Keys
    description: Secret and publishable API keys
  - name: Channels
    description: Sales channels and product publication across channels
  - name: Custom Fields
    description: >-
      Custom field definitions for products, variants, customers, and other
      resources
  - name: Customer Groups
    description: >-
      Customer groups for segmenting customers (e.g. wholesale, VIP) used by
      pricing and promotions
  - name: Customers
    description: Customer profiles, addresses, credit cards, and store credits
  - name: Exports
    description: Async CSV exports of admin resources
  - name: Fulfillments
    description: Order fulfillments — shipments, fulfill, cancel, resume, split
  - name: Gift Cards
    description: Gift cards and gift card batches
  - name: Markets
    description: >-
      Markets — geographic groupings of countries used for pricing, tax, and
      fulfillment rules
  - name: Option Types
    description: >-
      Option types and option values used to build product variants (e.g. Size,
      Color)
  - name: Orders
    description: Orders, order items, applied gift cards, and applied store credits
  - name: Payment Methods
    description: Configured payment providers and their available types
  - name: Payments
    description: Order payments — list, capture, void
  - name: Pricing
    description: >-
      Prices and price lists for currency-, market-, and customer-group-specific
      pricing
  - name: Products
    description: >-
      Products, taxons/categories, product custom field values, and bulk product
      operations
  - name: Promotions
    description: Promotions, promotion rules, promotion actions, and coupon codes
  - name: Refunds
    description: Order refunds
  - name: Settings
    description: Store-level settings — store profile, tags, store credit categories
  - name: Staff
    description: Admin users, roles, and invitations to the store
  - name: Stock Locations
    description: Warehouses and physical fulfillment locations
  - name: Variants
    description: >-
      Product variants — the individual SKUs (size/color combinations) sold
      under a product
  - name: Webhooks
    description: Webhook endpoints and webhook delivery history
paths:
  /api/v3/admin/products/{product_id}/variants:
    post:
      tags:
        - Variants
      summary: Create a variant
      description: >-
        Creates a new variant for a product. Supports nested prices and stock
        items.


        Option types and values are auto-created if they don't exist.

        Prices are upserted by currency. Stock items are upserted by stock
        location.



        **Required scope:** `write_products` (for API-key authentication).
      parameters:
        - name: x-spree-api-key
          in: header
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          required: true
          description: Bearer token for admin authentication
          schema:
            type: string
        - name: product_id
          in: path
          required: true
          description: Product ID
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - options
              properties:
                sku:
                  type: string
                  example: SKU-001
                cost_price:
                  type: string
                  example: '10.00'
                cost_currency:
                  type: string
                  example: USD
                weight:
                  type: number
                height:
                  type: number
                width:
                  type: number
                depth:
                  type: number
                weight_unit:
                  type: string
                dimensions_unit:
                  type: string
                track_inventory:
                  type: boolean
                tax_category_id:
                  type: string
                options:
                  type: array
                  description: >-
                    Required. A variant created here is always non-master, so it
                    must declare at least one option pair (e.g. size + color) or
                    creation fails with 422. One pair per option type the
                    variant participates in. Option types and values are
                    auto-created if missing.
                  items:
                    type: object
                    required:
                      - name
                      - value
                    properties:
                      name:
                        type: string
                        example: size
                      value:
                        type: string
                        example: Small
                position:
                  type: integer
                barcode:
                  type: string
                prices:
                  type: array
                  description: Per-currency prices. Upserted by currency.
                  items:
                    type: object
                    required:
                      - currency
                      - amount
                    properties:
                      currency:
                        type: string
                        example: USD
                      amount:
                        type: string
                        example: '29.99'
                      compare_at_amount:
                        type: string
                        nullable: true
                        example: '39.99'
                stock_items:
                  type: array
                  description: Per-stock-location inventory. Upserted by stock_location_id.
                  items:
                    type: object
                    required:
                      - stock_location_id
                      - count_on_hand
                    properties:
                      stock_location_id:
                        type: string
                        description: Stock location ID (e.g. sloc_xxx)
                      count_on_hand:
                        type: integer
                        example: 50
                      backorderable:
                        type: boolean
      responses:
        '201':
          description: variant created
          content:
            application/json:
              example:
                id: variant_EfhxLZ9ck8
                product_id: prod_UkLWZg9DAJ
                sku: NEW-SKU-001
                options_text: 'Size: XL'
                track_inventory: true
                media_count: 0
                preorder_ships_at: null
                thumbnail_url: null
                purchasable: false
                in_stock: false
                backorderable: false
                preorder: false
                weight: 0
                height: null
                width: null
                depth: null
                price:
                  id: price_EfhxLZ9ck8
                  amount: '24.99'
                  amount_in_cents: 2499
                  compare_at_amount: null
                  compare_at_amount_in_cents: null
                  currency: USD
                  display_amount: $24.99
                  display_compare_at_amount: null
                  price_list_id: null
                original_price: null
                option_values:
                  - id: optval_gbHJdmfrXB
                    option_type_id: opt_gbHJdmfrXB
                    name: xl
                    label: XL
                    position: 1
                    color_code: null
                    option_type_name: size
                    option_type_label: Size
                    image_url: null
                    metadata: {}
                    created_at: '2026-07-11T15:38:41.827Z'
                    updated_at: '2026-07-11T15:38:41.827Z'
                metadata: {}
                position: 3
                cost_price: null
                cost_currency: USD
                barcode: null
                weight_unit: lb
                dimensions_unit: null
                backorder_limit: null
                deleted_at: null
                created_at: '2026-07-11T15:38:41.831Z'
                updated_at: '2026-07-11T15:38:41.832Z'
                preorderable: false
                tax_category_id: taxcat_UkLWZg9DAJ
                available_stock: 0
                reserved_quantity: 0
                total_on_hand: 0
                product_name: Product 85741
        '422':
          description: validation error
          content:
            application/json:
              example:
                error:
                  code: validation_error
                  message: Option value variants can't be blank
                  details:
                    option_value_variants:
                      - can't be blank
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - api_key: []
          bearer_auth: []
      x-codeSamples:
        - lang: javascript
          label: Spree Admin SDK
          source: >-
            import { createAdminClient } from '@spree/admin-sdk'


            const client = createAdminClient({
              baseUrl: 'https://your-store.com',
              secretKey: 'sk_xxx',
            })


            const variant = await
            client.products.variants.create('prod_86Rf07xd4z', {
              sku: 'TSHIRT-L-NAVY',
              options: [
                { name: 'size', value: 'Large' },
                { name: 'color', value: 'navy' },
              ],
              prices: [
                { currency: 'USD', amount: '29.99', compare_at_amount: '34.99' },
                { currency: 'EUR', amount: '27.99' },
              ],
              stock_items: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 25 }],
            })
        - lang: bash
          label: Spree CLI
          source: >-
            spree api post /products/{product_id}/variants -d
            '{"sku":"TSHIRT-L-NAVY","options":[{"name":"size","value":"Large"},{"name":"color","value":"navy"}],"prices":[{"currency":"USD","amount":"29.99","compare_at_amount":"34.99"},{"currency":"EUR","amount":"27.99"}],"stock_items":[{"stock_location_id":"sloc_UkLWZg9DAJ","count_on_hand":25}]}'
components:
  schemas:
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              example: record_not_found
            message:
              type: string
              example: Record not found
            details:
              type: object
              description: Field-specific validation errors
              nullable: true
              example:
                name:
                  - is too short
                  - is required
                email:
                  - is invalid
          required:
            - code
            - message
      required:
        - error
      example:
        error:
          code: validation_error
          message: Validation failed
          details:
            name:
              - is too short
            email:
              - is invalid
  securitySchemes:
    api_key:
      type: apiKey
      name: x-spree-api-key
      in: header
      description: Secret API key for admin access
    bearer_auth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token for admin user authentication

````