Template Docs Commerce APIs Webhooks Tools
Get Started
Get Started

Create a product variant

POST https://api.squarespace.com/{api-version}/commerce/products/{id}/variants

Creates a variant of a physical product if the product has at least one attribute.

Note: Images cannot be specified when creating a new variant. See the "Related endpoints" section to learn how to assign a product image to a variant.

A successful request creates a ProductVariant subresource that belongs to the parent Product. Read the Overview to learn more about these resources.

Parameters

If needed, see the "Related endpoints" section to learn how to retrieve resource ids.

{api-version} string
required

See the Products API Overview page for the current API version.


{id} string
required

Specifies the Product that will own the ProductVariant.

Request example

Read the Making requests guide to learn why specific headers are necessary, and why some are omitted. Every request should also abide by Squarespace rate limits.

curl "https://api.squarespace.com/1.0/commerce/products/123/variants" \
  -i \
  -H "Authorization: Bearer YOUR_API_KEY_OR_OAUTH_TOKEN" \
  -H "User-Agent: YOUR_CUSTOM_APP_DESCRIPTION" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{' \
  # Required; string, 60 char limit.
  # Merchant-defined code that identifies the product variant.
  # Value must be unique among variants[]. Leading and trailing whitespace is removed.
  '"sku": "SQ0550273",' \
  # Required; object. Pricing data for the variant.
  '"pricing": {' \
    # Required; object. Amount per unit to charge for the variant.
    '"basePrice": {' \
      # Required; ISO 4217 currency code string.
      '"currency": "USD",' \
      # Required; string. Monetary amount.
      # Amount has no currency markers and conforms to the selected 
      # ISO currency's precision (e.g., JPY as 123; USD as 123.00 or 123).
      # Amount must not be more than 1,000,000.
      '"value": "10.95"' \
    '},' \
    # Optional; boolean.
    # Indicates whether the variant is sold according to its sale price.
    # If not specified, then the field defaults to `false` and the variant is not on sale.
    '"onSale": true,' \
    # Conditional; money object.
    # Amount per unit to charge when the variant is on sale.
    # Conditional; money object. Amount per unit charged when the variant is on sale.
    # If `onSale` is `false`, the field is not required.
    # If `onSale` is `true` then all salePrice fields are required.
    '"salePrice": {' \
      # Required; ISO 4217 currency code string.
      # If `onSale` is false; field defaults to the merchant site's currency setting.
      '"currency": "USD",' \
      # Required; string. Monetary amount.
      # Amount has no currency markers and conforms to the selected 
      # ISO currency's precision (e.g., JPY as 123; USD as 123.00 or 123).
      # Amount must not be more than 1,000,000.
      # If `onSale` is false, field coalesces to the lesser of this and `basePrice.value`.
	 '"value": "7.99"' \
    '}' \
  '},' \
  # Optional; object. Available stock for the variant.
  # If stock isn’t provided, then the new variant uses the default values as described.
  '"stock": {' \
    # Optional; integer, value must be less than 1,000,000,000.
    # Number of units that can be purchased.
    # If not specified, the new variant is not in stock.
    '"quantity": 10,' \
    # Optional; boolean.
    # Indicates whether the variant has unlimited stock.
    # If `true`, the quantity for the new variant is zero.
    '"unlimited": false' \
  },
  # Conditional; object of key-value pairs,
  # 100 char limit per key and per value with no more than six key-value pairs.
  # Specifies attribute-value pairs for the variant.
  # Read the guide below to learn about request validations
  # between this field and the product's attributes.
  # https://developers.squarespace.com/commerce-apis/manage-attributes
  '"attributes": {' \
    '"Flavor": "BBQ"' \
  '},' \
  # Optional; object. Measurements of the variant when it's shipped.
  # Values are used for calculating shipping costs at checkout.
  '"shippingMeasurements": {' \
    # Optional; object. Weight of the variant.
    # If not specified, then the new variant uses the default
    # values described below. Otherwise, all weight fields are required.
    '"weight": {' \
      # Required; string. Unit of measurement.
      # Supported values: `KILOGRAM`, `POUND`,  but it must be based on the merchant site’s
      # measurement standard (e.g. use `KILOGRAM` for the metric system).
      # To retrieve the measurement standard, visit the FAQ link and scroll to
      # ‘How can I determine the Squarespace site that owns a particular API key or OAuth token?`
      # https://developers.squarespace.com/commerce-apis/faq
      '"unit": "POUND",' \
      # Required; decimal. Weight amount.
      # Value must be less than 10,000 and rounded to the nearest ten thousandth.
      # If not specified, then value defaults to 0.0 for the product variant.
      '"value": 1.0' \
    '},' \
    # Optional; object. Physical dimensions of the variant.
    # If not specified, then the new variant uses the default values described below.
    # Otherwise, all dimensions fields are required and each decimal field
    # must be less than 10,000 and rounded to the nearest ten thousandth.
    '"dimensions": {' \
      # Required; string. Unit of measurement.
      # Supported values: `CENTIMETER`,  `INCH`, but it must be based on the merchant site’s
      # measurement standard (e.g. use `CENTIMETER` for the metric system).
      # To retrieve the measurement standard, visit the FAQ link and scroll to
      # ‘How can I determine the Squarespace site that owns a particular API key or OAuth token?`
      # https://developers.squarespace.com/commerce-apis/faq
      '"unit": "INCH",' \
      # Required; decimal. Length of the variant; defaults to 0.0.
      '"length": 3.0,' \
      # Required; decimal. Width of the variant; defaults to 0.0.
      '"width": 8.0,' \
      # Required; decimal. Height of the variant; defaults to 0.0.
      '"height": 11.0' \
    '}' \
  '}' \
'}'

Response example

A response to a successful request will contain the ProductVariant.

{
  // Unique ProductVariant id.
  "id": "6b76dad2-a15a-4dfc-97e1-47427e12061f",
  // Merchant-defined code that identifies the product variant.
  "sku": "SQ0557856",
  // Pricing data for the variant.
  "pricing": {
    // Amount per unit charged for the variant.
    "basePrice": {
      // ISO 4217 currency code string.
      "currency": "USD",
      // Monetary amount.
      "value": "12.95"
    },
    // Amount per unit charged when the variant is on sale.
    "salePrice": {
      // ISO 4217 currency code string.
      // If `onSale` is false; field defaults to the merchant site's currency setting.
      "currency": "USD",
      // Monetary amount.
      // If `onSale` is false, field coalesces to the lesser of this and `basePrice.value`.
      "value": "0.00"
    },
    // Indicates whether the variant is sold according to its sale price.
    "onSale": false
  },
  // Available stock for the variant.
  "stock": {
    // Number of units that can be purchased.
    "quantity": 10,
    // Indicates whether the variant has unlimited stock.
    "unlimited": false
  },
  // Specifies attribute-value pairs for the variant.
  "attributes": {
    "Flavor": "Habanero"
  },
  // Measurements of the variant when it's shipped.
  "shippingMeasurements": {
    // Weight of the variant.
    "weight": {
      // Unit of measurement.
      // Supported values: `KILOGRAM`, `POUND`.
      "unit": "POUND",
      // Weight amount.
      "value": 2.0
    },
    // Physical dimensions of the variant.
    "dimensions": {
      // Unit of measurement.
      // Supported values: `INCH`, `CENTIMETER`.
      "unit": "INCH",
      // Length of the variant.
      "length": 7.0,
      // Width of the variant.
      "width": 5.0,
      // Height of the variant.
      "height": 5.0
    }
  },
  // Product image assigned to the variant.  
  "image": null
}

Status codes and error conditions

201 CREATED

The request was successful. The message body contains data in the format specified above.


400 BAD REQUEST

Type: INVALID_REQUEST_ERROR

Subtype: null
The request body does not conform to the required specification.


404 NOT FOUND

Type: INVALID_REQUEST_ERROR

Subtype: INVALID_ARGUMENT
The requested Product was not found.


405 METHOD NOT ALLOWED

Type: METHOD_NOT_ALLOWED

Subtype: OPERATION_NOT_ALLOWED_FOR_PRODUCT_TYPE
The Product requested is not a physical Product.


409 CONFLICT

Type: CONFLICT

Subtype: SKU_UNAVAILABLE
The provided SKU is already in use by the requested Product.

Subtype: VARIANT_LIMIT_REACHED
The Product has reached its limit of 100 variants.

Related endpoints

Ids
To retrieve ids for Products, use the retrieve all products endpoint.

Images
Use the assign a product image to a variant endpoint.