Shopify API: Create A New Product Variant

Shopify API: Create A New Product Variant

Variant is a new version of the product. Example: Colors or sizes. If you don’t create a new variant, you will have to treat shirts with 3 colors yellow, blue, green as 3 separate products. Product Variant allows you to treat yellow, blue and green shirts as 3 variations of the same product as a shirt.

Each product has a maximum of 100 variants. For every business running on Shopify, the creation of new variants is required. So, today I will show you how to create a new variant in Shopify using Postman.

Step 1 : Generate API credentials from the Shopify admin

Generate API credentials from the Shopify admin
  • Click Create a new private app
  • In the App details section, enter a name for your app, and an emergency developer email
  • In the Admin API section, select the areas of your store that you want the app to access
Generate API credentials from the Shopify admin
  • Click Save

The Admin API section displays the app’s API key and password when you save the app’s details.

Step 2: Create A New Product Variant

  • Log in to your Postman and create new workspace
  • Create new POST with this URL:
https://{username}:{password}@{shop}.myshopify.com/admin/api/{api-version}/{resource}.json
  1. {username} – The API key that you generated.
  2. {password} – The API password that you generated.
  3. {shop} – The name of your development store.
  4. {api-version} – The supported API version that you want to use.
  5. {resource} – A resource endpoint from the REST Admin API.

Or you can copy this example in the Shopify Admin, remember change {resource} to {products/product ID/variants}:

https://33a72f01e02987636e1c1a9a4e95c840:[email protected]/admin/api/2021-10/products/4356051664959/variants.json
Example URL
  • Paste the URL above.
Post

In the body section, enter this code, then click Send.

{
    "variant": {
        "option1": "Yellow",
        "price": "1.00"
    }
}

Response:

API will return the data like this.

{
    "variant": {
        "id": 39525900648511,
        "product_id": 4356051664959,
        "title": "Yellow",
        "price": "1.00",
        "sku": "",
        "position": 2,
        "inventory_policy": "deny",
        "compare_at_price": null,
        "fulfillment_service": "manual",
        "inventory_management": "shopify",
        "option1": "Yellow",
        "option2": null,
        "option3": null,
        "created_at": "2021-11-24T11:31:58+09:00",
        "updated_at": "2021-11-24T11:31:58+09:00",
        "taxable": true,
        "barcode": null,
        "grams": 0,
        "image_id": null,
        "weight": 0.0,
        "weight_unit": "kg",
        "inventory_item_id": 41620530987071,
        "inventory_quantity": 0,
        "old_inventory_quantity": 0,
        "requires_shipping": true,
        "admin_graphql_api_id": "gid://shopify/ProductVariant/39525900648511"
    }
}
Response

Step 3: Verify the result

In the admin, choose products, click all products, then search product by product id. 

Look at the variant area.

Variants area

As you can see the new product variant has been created.

I have shown you all steps to create a new product variant with Shopify API using Postman. If you have any questions please leave a comment below or refer to our Devdocs

If you still do not understand the tutorial’s content, you can watch the video below for a more overview.

Shopify API: Create a new product variant

Hopefully you can do it!

Related Articles

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email