On Thursday October 25th, Shopify will start introducing Product Cost. This feature enables merchants to record the unit cost of their variants, track margin, and report on product performance within Shopify. This feature will roll out to all stores over the next few days.
Merchants will see a new cost per item field when editing variant pricing and will be able to bulk update this cost via the product CSV importer and the product bulk editor. There will also be changes to analytics, including the addition of new Profit Margin, Cost of Goods, and Gross Profit reports.
In order to enable our partners to leverage this feature in their apps we are exposing a new cost property on the InventoryItem. Please see the examples below for implementation details.
GraphQL
To pass Shopify the unit cost of a variant via the GraphQL Admin API you will use the productVariantUpdate mutation, see example below.
Mutation:
mutation productVariantUpdate($input: ProductVariantInput!) {
productVariantUpdate(input: $input) {
userErrors {
field
message
}
productVariant {
id
}
}
}
Input variables:
{
"input": {
"id": "gid://shopify/ProductVariant/35437260802",
"inventoryItem": {
"cost": "25.00"
}
}
}
For more information about variant mutations please see our documentation.
REST
To pass Shopify the unit cost of a variant using our REST Admin API you will use the InventoryItem endpoint, see example below.
PUT /admin/inventory_items/#{inventory_item_id}.json
{
"inventory_item": {
"id": 808950810,
"cost": "25.00"
}
}
For more InventoryItem endpoint information see our documentation.
As always, if you have any questions, or concerns, please don't hesitate to reply in the thread below.
Hi, Kieran!
This seemed like good news initially, but...
For us, the concern is (the same as with Multi-Location Inventory) the following - to read and write this value, that would require additional API call for each of variant inventory items.
Making the request complexity to be N+1 - as many requests as there are variants.
The suggestion (and expectation from us as API "customers") would be that this is the read+write attribute of the variant.
Earlier we suggested clients to store their "cost" in Variant Metafields which also is N+1 complexity, and my hope when reading this post, was to have good news for clients that now they can update their cost much faster with this attribute.
Can we update this attribute for all the variants of one product with one single request?
Thanks!
Hi Maris & Danijel,
Glad that you both welcome this change. In terms of bulk updates to the cost property, I would suggest going the GraphQL route where you can add the cost on create and update for multiple variants.
Here's an example of creating a product with two variants and setting the variant's inventory item cost:
Mutation:
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
id
}
}
}
Input variables:
{
"input": {
"title": "Product",
"variants": [{
"title": "Variant 1",
"options": "Red",
"price": "55.00",
"inventoryItem": {
"cost": "33.00"
}
},
{
"title": "Variant 2",
"options": "Blue",
"price": "55.00",
"inventoryItem": {
"cost": "33.00"
}
}]
}
}
The same principle applies with the updateProduct mutation as well.
I hope that helps!
As others have said, a very welcome change! Well done to the team!
From a business use perspective, one further request is to enable calculation of profit margins based on Product Prices that are exclusive of tax.
Example:
Hi Kieran,
Would the `cost` field be availabe in the `Variant` API endpoint by any chance (even just as a read-only attribute)?
This would save us an additional API call to the InventoryItem just to pull the data (we have a reporting app).
Thanks!
Well done! I think a lot of merchants will be super happy about that.
I have to second others comment regarding bulk loading.
I have wondered since day one of the multi-location feature why the inventory item entity is not merged into the variant entity since there is a 1-1 relationship between them.
Unless there is a plan to enable inventory of non-variants in the future?