Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Cost per item can be updated from the Product API

Cost per item can be updated from the Product API

radulescuandrew
Shopify Partner
4 0 4

There are many topics regarding Cost Per item for a Product. 

 

The documentation is missing the part where you can include the "Cost" property in a variant and will update the "Cost Per Item".

 

 

{
  id: <id>,
  sku: <sku>,
  name: <some name>
  price: <price>,
  cost: Unit_Cost ?? 0
}

 

 

Is this omitted intentionally or it's a subject for change in the future?
Clearly, we can make use of the "inventory_items" PUT method to update the Cost but will take twice the time to make the update. 

 

What are your thoughts ShopifyTeam? 

 

+@dragos1195 

Replies 3 (3)

SB_90
Shopify Partner
216 52 70

Hi @radulescuandrew 

 

I suspect this will likely be a job for the GraphQL API.

 

A representative (non working) example may be something like this where you include the inventoryItem property within the variants array when creating the product:

 

mutation($input:ProductInput){
  productCreate(input:{
    handle: "example-product",
		...
    variants:[
      {
        title:"Example Product Variant 1",
				...
        inventoryItem:{
          cost: 10.05,
          tracked: true
        }
      }
    ]		
  }){
    product{
      id
      variants{
        nodes{
          inventoryItem{
            unitCost{
              amount
              currencyCode
            }
          }
        }
      }
    }
  }
}

 

As I said - it's a non working example, but theoretically it's possible to create the product with those cost prices in one call using GraphQL.

radulescuandrew
Shopify Partner
4 0 4

Thanks, @SB_90, but I think you misunderstood my question.

 

The problem is the documentation is missing the "Cost" field, but it's working. The payload I provided is valid and it's updating the cost as I want to.

 

I'm grateful that is working, everything is fine, but I'm curious if this is subject to change in the future so I'll not be surprised if my solution is not working anymore.

 

 

bretto36
Shopify Partner
5 0 2

The value continues to be able to be updated by providing cost in the payload on a variant... but it never shows the cost on the variant on a GET request. So i wonder if they could put that in as well so that the functionality matches with POST and GET