A 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, and 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, new variants are required. So, today I will show you how to create a new product variant using Postman in Shopify.
Step 1: Generate API credentials from the Shopify admin
- Log in to your Shopify admin
- Go to Apps – Manage private apps
- 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
- 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 a new workspace
-
- Create a new POST with this URL:
https://{username}:{password}@{shop}.myshopify.com/admin/api/{api-version}/{resource}.json
-
- {username} – The API key that you generated.
-
- {password} – The API password that you generated.
-
- {shop} – The name of your development store.
-
- {api-version} – The supported API version that you want to use.
-
- {resource} – A resource endpoint from the REST Admin API.
Or you can copy this example in the Shopify Admin, remember to change {resource} to {products/product ID/variants}:
https://33a72f01e02987636e1c1a9a4e95c840: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@hexasync.myshopify.com/admin/api/2021-10/products/4356051664959/variants.json
-
- Paste the URL above.
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"
}
}
Step 3: Verify the result
In the admin, choose products, click all products, then search product by product id.
Look at the variant area.
As you can see, the new product variant has been created.
I have shown you all steps to create a new product variant using Postman with Shopify API . If you have any questions, please 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.
Hopefully, you can do it!