---
displayed_sidebar: jsClientSidebar
slug: /references/js-client/ProductVariantsResource
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# ProductVariantsResource

This class is used to send requests to [Store Product Variant API Routes](https://docs.medusajs.com/api/store#product-variants). All its method
are available in the JS Client under the `medusa.product.variants` property.

Product variants are the actual salable item in your store. Each variant is a combination of the different option values available on the product.

## Methods

### list

Retrieves a list of product variants. The product variants can be filtered by fields such as `id` or `title` passed in the `query` parameter. The product variants can also be paginated.

For accurate and correct pricing of the product variants based on the customer's context, it's highly recommended to pass fields such as
`region_id`, `currency_code`, and `cart_id` when available.

Passing `sales_channel_id` ensures retrieving only variants of products available in the specified sales channel.
You can alternatively use a publishable API key in the request header instead of passing a `sales_channel_id`.

#### Example

To list product variants:

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.product.variants.list()
.then(({ variants }) => {
  console.log(variants.length);
})
```

To specify relations that should be retrieved within the product variants:

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.product.variants.list({
  expand: "product"
})
.then(({ variants }) => {
  console.log(variants.length);
})
```

By default, only the first `100` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.product.variants.list({
  expand: "product",
  limit,
  offset
})
.then(({ variants }) => {
  console.log(variants.length);
})
```

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "query",
    "type": "[StoreGetVariantsParams](../../medusa/classes/medusa.StoreGetVariantsParams.mdx)",
    "description": "Filters and pagination configurations applied on the retrieved product variants.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "cart_id",
        "type": "`string`",
        "description": "Retrieve prices for a cart ID.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "currency_code",
        "type": "`string`",
        "description": "Retrieve prices for a currency code.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "expand",
        "type": "`string`",
        "description": "Comma-separated relations that should be expanded in the returned data.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "fields",
        "type": "`string`",
        "description": "Comma-separated fields that should be included in the returned data.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "id",
        "type": "`string` \\| `string`[]",
        "description": "IDs to filter product variants by.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "ids",
        "type": "`string`",
        "description": "ID to filter the product variants by.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "inventory_quantity",
        "type": "`number` \\| [NumericalComparisonOperator](../../medusa/classes/medusa.NumericalComparisonOperator.mdx)",
        "description": "Number filters to apply on the product variants' `inventory_quantity` field.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "limit",
        "type": "`number`",
        "description": "Limit the number of items returned in the list.",
        "optional": true,
        "defaultValue": "100",
        "expandable": false,
        "children": []
      },
      {
        "name": "offset",
        "type": "`number`",
        "description": "The number of items to skip when retrieving a list.",
        "optional": true,
        "defaultValue": "0",
        "expandable": false,
        "children": []
      },
      {
        "name": "region_id",
        "type": "`string`",
        "description": "Retrieve prices for a region ID.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "sales_channel_id",
        "type": "`string`",
        "description": "Filter product variants by the ID of their associated sales channel.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "title",
        "type": "`string` \\| `string`[]",
        "description": "Titles to filter product variants by.",
        "optional": true,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;StoreVariantsListRes&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the list of product variants.",
    "expandable": false,
    "children": [
      {
        "name": "variants",
        "type": "[PricedVariant](../../medusa/types/medusa.PricedVariant.mdx)[]",
        "description": "An array of product variant descriptions.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />

___

### retrieve

Retrieve a Product Variant's details. For accurate and correct pricing of the product variant based on the customer's context, it's highly recommended to pass fields such as
`region_id`, `currency_code`, and `cart_id` when available.

Passing `sales_channel_id` ensures retrieving only variants of products available in the current sales channel.
You can alternatively use a publishable API key in the request header instead of passing a `sales_channel_id`.

#### Example

```ts
import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.product.variants.retrieve(productVariantId)
.then(({ variant }) => {
  console.log(variant.id);
})
```

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "The ID of the product variant.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customHeaders",
    "type": "`Record<string, any>`",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} expandUrl="https://docs.medusajs.com/js-client/overview#expanding-fields"/>

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "ResponsePromise&#60;StoreVariantsRes&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the product variant's details.",
    "expandable": false,
    "children": [
      {
        "name": "variant",
        "type": "[PricedVariant](../../medusa/types/medusa.PricedVariant.mdx)",
        "description": "Product variant description.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />
