Brandon
Brandon

Reputation: 3707

How to Find the Variant ID of a Product Variant for the Squarespace Commerce API

While using the Squarespace Commerce APIs in order to adjust inventory of a product variant, the Inventory API requires a variant ID to be sent with the request. How does one go about obtaining the variant ID for a product variant?

Upvotes: 1

Views: 653

Answers (1)

Brandon
Brandon

Reputation: 3707

There are a few ways to get a variant's ID:

Option 1: Make a request using the Squarespace Inventory API using the API Key you created as authorization header. The response will contain product/variant information, including variant IDs. enter image description here


Option 2: Go to the page for the product/item in question in a not-logged-in window. Then, add ?format=json-pretty to the URL. Then go to item > structuredContent > variants. Find the variant number in the variants array by comparing sku or attributes properties. Once you've found it, grab that item's id value. That is the variant ID. enter image description here

Option 3: While logged in and editing your site, edit the product in question, go to "Pricing & Variants" and use your browser's developer tools to select the specific variant's image. That div will have an id attribute of the variant's ID. enter image description here

Note that there are likely other places within the front-end and back-end code that the variantID shows up and can be obtained using dev. tools, such as in the variant drop-down on the details page for a product.

Upvotes: 1

Related Questions