New cost property on InventoryItem

Highlighted
Shopify Staff
Shopify Staff
22 0 11

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.

4 Likes
Shopify Partner
285 0 25

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!

Excelify.io | Bulk Import Export Update Migrate | https://excelify.io
1 Like
Excursionist
20 0 15

Good change. This will be useful.

I strongly agree that the api needs support for batch operations. That, or relax the frustratingly low rate limit. 

0 Likes
Shopify Staff
Shopify Staff
22 0 11

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!

2 Likes
Shopify Partner
285 0 25

Yey, that's great, Kieran!

That's just what's needed!

Thanks!

Excelify.io | Bulk Import Export Update Migrate | https://excelify.io
0 Likes
Tourist
3 0 1

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:

  • A store's product prices are stored inclusive of tax
  • "All taxes are included in my prices" is checked in Taxes settings
  • Provide a store setting to use the tax-exclusive product prices when calculating profit
0 Likes
New Member
1 0 0

Hi there.  Will we be able to inupt/update this info via Transfer?  Also, will the COG update as they either increase/decrease depending on existing vs new stock?

0 Likes
Shopify Partner
5 0 0

Will the cost data be surfaced in the order admin? I applied a cost to a variant, then placed an order, and don't see any cost, margin or profit data anywhere. 

0 Likes
Pathfinder
118 4 18

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!

2 Likes
Shopify Partner
660 0 100

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?

0 Likes