> ## 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: Categories
    description: >-
      Hierarchical product categories — tree management, repositioning, and
      product assignments
  - name: Channels
    description: >-
      Sales channels, product publication across channels, and per-channel order
      routing rules
  - 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: Email Templates
    description: >-
      Customer email templates, the email layout and shared partials: drafts,
      previews, publishing and history
  - name: Exports
    description: Async CSV exports of admin resources
  - name: Files
    description: Uploading the files that product media, imports, logos and documents use
  - name: Fulfillments
    description: Order fulfillments — shipments, fulfill, cancel, resume, split
  - name: Gift Cards
    description: Gift cards and gift card batches
  - name: Imports
    description: >-
      Async CSV imports of admin resources, with per-row status and failed-row
      retry
  - name: Maintenance Tasks
    description: >-
      Operator-run data work — backfills, reindexes and upgrade steps — and the
      record of every run
  - 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: Policies
    description: The store's legal documents — terms of service, privacy, returns, shipping
  - name: Reasons
    description: >-
      Merchant-owned vocabularies for why a return, claim, refund, cancellation
      or tax exemption happened
  - 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, and configuration
  - name: Staff
    description: Admin users, roles, and invitations to the store
  - name: Stock Locations
    description: Warehouses and physical fulfillment locations
  - name: Store Credits
    description: Prepaid customer balances across all customers, and each balance's ledger
  - 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:
              $ref: '#/components/schemas/VariantCreateParams'
        required: true
      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
                weight_unit: lb
                dimensions_unit: in
                minimum_order_quantity: null
                order_multiple: null
                purchase_unit: null
                units_per_carton: null
                price:
                  id: price_EfhxLZ9ck8
                  currency: USD
                  amount: '24.99'
                  compare_at_amount: null
                  price_list_id: null
                  min_quantity: 1
                  variant_id: variant_EfhxLZ9ck8
                  created_at: '2026-01-15T12:00:00.000Z'
                  updated_at: '2026-01-15T12:00:00.000Z'
                original_price: null
                seller_id: 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-01-15T12:00:00.000Z'
                    updated_at: '2026-01-15T12:00:00.000Z'
                external_references: {}
                metadata: {}
                position: 3
                cost_currency: USD
                barcode: null
                backorder_limit: null
                hs_code: null
                country_of_origin: null
                customs_description: null
                carton_weight: null
                cartons_per_pallet: null
                deleted_at: null
                created_at: '2026-01-15T12:00:00.000Z'
                updated_at: '2026-01-15T12:00:00.000Z'
                cost_price: null
                preorderable: false
                tax_category_id: null
                carton_package_type_id: null
                units_per_pallet: null
                available_stock: 0
                reserved_quantity: 0
                total_on_hand: 0
                product_name: Product 2151771
                delivery_profile_id: fp_UkLWZg9DAJ
        '422':
          description: validation error
          content:
            application/json:
              example:
                error:
                  code: validation_error
                  message: SKU has already been taken
                  details:
                    sku:
                      - value: SKU-290
                        code: taken
                        message: has already been taken
                        specific: false
              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_levels: [{ 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_levels":[{"stock_location_id":"sloc_UkLWZg9DAJ","count_on_hand":25}]}'
components:
  schemas:
    VariantCreateParams:
      allOf:
        - $ref: '#/components/schemas/VariantParams'
        - type: object
          properties:
            options:
              type: array
              items:
                $ref: '#/components/schemas/VariantOptionParams'
              description: >-
                One pair per option type the variant takes part in (size,
                color). Option types and values are created when missing. On
                update, omit to leave the option values untouched.
            external_references:
              type: object
              additionalProperties: true
              description: >-
                Identities the record has in external systems, keyed by system:
                the same `{ system: external_id }` map the Admin API renders, so
                what you read can be sent straight back. Systems you do not name
                keep the reference they have. A list of `{ system, external_id
                }` entries is accepted too.
          required:
            - options
    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
    VariantParams:
      type: object
      properties:
        sku:
          type: string
        barcode:
          type: string
        cost_price:
          type: string
          format: decimal
          pattern: ^-?\d+(\.\d+)?$
          nullable: true
        cost_currency:
          $ref: '#/components/schemas/CurrencyCode'
        weight:
          type: number
          nullable: true
        height:
          type: number
          nullable: true
        width:
          type: number
          nullable: true
        depth:
          type: number
          nullable: true
        weight_unit:
          allOf:
            - $ref: '#/components/schemas/WeightUnit'
          description: Null falls back to the store's weight unit.
          nullable: true
        dimensions_unit:
          allOf:
            - $ref: '#/components/schemas/DimensionUnit'
          description: Null falls back to the store's unit system.
          nullable: true
        hs_code:
          type: string
        customs_description:
          type: string
        country_of_origin:
          $ref: '#/components/schemas/CountryCode'
        minimum_order_quantity:
          type: integer
          nullable: true
        order_multiple:
          type: integer
          nullable: true
        purchase_unit:
          type: string
          nullable: true
          enum:
            - unit
            - carton
        units_per_carton:
          type: integer
          description: How many units fill one carton.
          nullable: true
        carton_package_type_id:
          type: string
          description: >-
            The carton this variant is packed into: a package type of kind
            `carton`. Its dimensions are shared by every product packed the same
            way, so a corrected carton size fixes all of them at once.
          nullable: true
        carton_weight:
          type: number
          description: What one packed carton weighs, in the variant's weight unit.
          nullable: true
        cartons_per_pallet:
          type: integer
          description: How many cartons stack on one pallet.
          nullable: true
        track_inventory:
          type: boolean
        preorderable:
          type: boolean
          description: >-
            Sell this variant before it's in stock. Adds the pre-order label and
            ships-by promise; the cap comes from `backorder_limit`, an incoming
            stock count, or backorder.
        preorder_ships_at:
          type: string
          format: date-time
          description: >-
            The "ships by" date shown to customers while the variant is a
            pre-order. Once it passes, the variant is no longer a pre-order.
            Null clears it.
          nullable: true
        backorder_limit:
          type: integer
          description: >-
            Maximum units sellable beyond available stock, capping backorders
            and pre-orders. Null is unlimited.
          nullable: true
        position:
          type: integer
        options:
          type: array
          items:
            $ref: '#/components/schemas/VariantOptionParams'
          description: >-
            One pair per option type the variant takes part in (size, color).
            Option types and values are created when missing.
        seller_id:
          type: string
        delivery_profile_id:
          type: string
          nullable: true
        tax_category_id:
          type: string
        prices:
          type: array
          items:
            $ref: '#/components/schemas/PriceParams'
          description: Per-currency prices. Upserted by currency.
        stock_levels:
          type: array
          items:
            $ref: '#/components/schemas/StockLevelParams'
          description: >-
            Stock per location. Upserted by location; omitted locations are
            removed.
    VariantOptionParams:
      type: object
      properties:
        name:
          type: string
          example: size
        value:
          type: string
          example: Small
      required:
        - name
        - value
    CurrencyCode:
      type: string
      enum:
        - AED
        - AFN
        - ALL
        - AMD
        - ANG
        - AOA
        - ARS
        - AUD
        - AWG
        - AZN
        - BAM
        - BBD
        - BDT
        - BGN
        - BHD
        - BIF
        - BMD
        - BND
        - BOB
        - BRL
        - BSD
        - BTN
        - BWP
        - BYN
        - BYR
        - BZD
        - CAD
        - CDF
        - CHF
        - CLF
        - CLP
        - CNY
        - COP
        - CRC
        - CUC
        - CUP
        - CVE
        - CZK
        - DJF
        - DKK
        - DOP
        - DZD
        - EEK
        - EGP
        - ERN
        - ETB
        - EUR
        - FJD
        - FKP
        - GBP
        - GEL
        - GHS
        - GIP
        - GMD
        - GNF
        - GTQ
        - GYD
        - HKD
        - HNL
        - HRK
        - HTG
        - HUF
        - IDR
        - ILS
        - INR
        - IQD
        - IRR
        - ISK
        - JMD
        - JOD
        - JPY
        - KES
        - KGS
        - KHR
        - KMF
        - KPW
        - KRW
        - KWD
        - KYD
        - KZT
        - LAK
        - LBP
        - LKR
        - LRD
        - LSL
        - LTL
        - LVL
        - LYD
        - MAD
        - MDL
        - MGA
        - MKD
        - MMK
        - MNT
        - MOP
        - MRO
        - MRU
        - MTL
        - MUR
        - MVR
        - MWK
        - MXN
        - MYR
        - MZN
        - NAD
        - NGN
        - NIO
        - NOK
        - NPR
        - NZD
        - OMR
        - PAB
        - PEN
        - PGK
        - PHP
        - PKR
        - PLN
        - PYG
        - QAR
        - RON
        - RSD
        - RUB
        - RWF
        - SAR
        - SBD
        - SCR
        - SDG
        - SEK
        - SGD
        - SHP
        - SKK
        - SLE
        - SLL
        - SOS
        - SRD
        - SSP
        - STD
        - STN
        - SVC
        - SYP
        - SZL
        - THB
        - TJS
        - TMM
        - TMT
        - TND
        - TOP
        - TRY
        - TTD
        - TWD
        - TZS
        - UAH
        - UGX
        - USD
        - UYI
        - UYU
        - UYW
        - UZS
        - VED
        - VEF
        - VES
        - VND
        - VUV
        - WST
        - XAF
        - XCD
        - XCG
        - XOF
        - XPF
        - YER
        - ZAR
        - ZMK
        - ZMW
        - ZWD
        - ZWG
        - ZWL
        - ZWN
        - ZWR
    WeightUnit:
      type: string
      enum:
        - g
        - kg
        - lb
        - oz
    DimensionUnit:
      type: string
      enum:
        - mm
        - cm
        - in
        - ft
    CountryCode:
      type: string
      enum:
        - AD
        - AE
        - AF
        - AG
        - AI
        - AL
        - AM
        - AO
        - AR
        - AS
        - AT
        - AU
        - AW
        - AZ
        - BA
        - BB
        - BD
        - BE
        - BF
        - BG
        - BH
        - BI
        - BJ
        - BL
        - BM
        - BN
        - BO
        - BQ
        - BR
        - BS
        - BT
        - BW
        - BY
        - BZ
        - CA
        - CC
        - CD
        - CF
        - CG
        - CH
        - CI
        - CK
        - CL
        - CM
        - CN
        - CO
        - CR
        - CU
        - CV
        - CW
        - CX
        - CY
        - CZ
        - DE
        - DJ
        - DK
        - DM
        - DO
        - DZ
        - EC
        - EE
        - EG
        - ER
        - ES
        - ET
        - FI
        - FJ
        - FK
        - FM
        - FO
        - FR
        - GA
        - GB
        - GD
        - GE
        - GF
        - GG
        - GH
        - GI
        - GL
        - GM
        - GN
        - GP
        - GQ
        - GR
        - GT
        - GU
        - GW
        - GY
        - HK
        - HN
        - HR
        - HT
        - HU
        - ID
        - IE
        - IL
        - IM
        - IN
        - IQ
        - IR
        - IS
        - IT
        - JE
        - JM
        - JO
        - JP
        - KE
        - KG
        - KH
        - KI
        - KM
        - KN
        - KP
        - KR
        - KW
        - KY
        - KZ
        - LA
        - LB
        - LC
        - LI
        - LK
        - LR
        - LS
        - LT
        - LU
        - LV
        - LY
        - MA
        - MC
        - MD
        - ME
        - MF
        - MG
        - MH
        - MK
        - ML
        - MM
        - MN
        - MO
        - MP
        - MQ
        - MR
        - MS
        - MT
        - MU
        - MV
        - MW
        - MX
        - MY
        - MZ
        - NA
        - NC
        - NE
        - NF
        - NG
        - NI
        - NL
        - 'NO'
        - NP
        - NR
        - NU
        - NZ
        - OM
        - PA
        - PE
        - PF
        - PG
        - PH
        - PK
        - PL
        - PM
        - PN
        - PR
        - PS
        - PT
        - PW
        - PY
        - QA
        - RE
        - RO
        - RS
        - RU
        - RW
        - SA
        - SB
        - SC
        - SD
        - SE
        - SG
        - SH
        - SI
        - SJ
        - SK
        - SL
        - SM
        - SN
        - SO
        - SR
        - SS
        - ST
        - SV
        - SX
        - SY
        - SZ
        - TC
        - TD
        - TG
        - TH
        - TJ
        - TK
        - TL
        - TM
        - TN
        - TO
        - TR
        - TT
        - TV
        - TW
        - TZ
        - UA
        - UG
        - US
        - UY
        - UZ
        - VA
        - VC
        - VE
        - VG
        - VI
        - VN
        - VU
        - WF
        - WS
        - YE
        - YT
        - ZA
        - ZM
        - ZW
    PriceParams:
      type: object
      properties:
        currency:
          allOf:
            - $ref: '#/components/schemas/CurrencyCode'
          example: USD
        amount:
          type: string
          format: decimal
          pattern: ^-?\d+(\.\d+)?$
          description: >-
            A canonical decimal string (`"1234.56"`: period decimal, no
            grouping). The API does not parse localized input.
          example: '29.99'
        compare_at_amount:
          type: string
          format: decimal
          pattern: ^-?\d+(\.\d+)?$
          example: '39.99'
          nullable: true
      required:
        - currency
        - amount
    StockLevelParams:
      type: object
      properties:
        stock_location_id:
          type: string
          description: The location holding the stock (`sloc_...`).
        count_on_hand:
          type: integer
          description: >-
            Units physically at the location, not units available to sell: stock
            promised to placed orders counts until it ships. Sent as the count
            the shelf should end at; the API records the difference as an
            adjustment in the stock history.
        backorderable:
          type: boolean
          description: Whether this location sells the variant beyond what it holds.
      required:
        - stock_location_id
        - count_on_hand
  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

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.