A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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?
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.
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.
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