A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi,
I wrote a python script that udates the product prices using graphql requests and it works fine where there is a product variant.
But i can't figure out how to update the price if there is no variant.
I know by design the products without variants have a "default variant" but whats the id of this?
If i pass the product id itself then i get an "invalidID" error back
I can't find anything in the documentation on this.
Thanks
Solved! Go to the solution
This is an accepted solution.
Hi @thearchitect :
All products in Shopify have variant ( in simple products it will be just one Variant ).
So you need to approach in following steps :
1. From product ID query get variant.
{
product(id: "gid://shopify/Product/8119795253543"){
variants(first:5 ){
nodes {
id
price
}
}
}
}
2. Using GraphQl mutation now you can update the variant price.
Thanks,
This is an accepted solution.
Hi @thearchitect :
All products in Shopify have variant ( in simple products it will be just one Variant ).
So you need to approach in following steps :
1. From product ID query get variant.
{
product(id: "gid://shopify/Product/8119795253543"){
variants(first:5 ){
nodes {
id
price
}
}
}
}
2. Using GraphQl mutation now you can update the variant price.
Thanks,
Query to Update Product Price...
mutation {
productUpdate(input: {id: "gid://shopify/Product/8148348436784",
variants:{
price:300.00
}
}) {
product {
id
}
}
}
Hey I need a quick help, Actually When I pasted your this query
mutation {
productUpdate(input: {id: "gid://shopify/Product/8148348436784",
variants:{
price:300.00
}
}) {
product {
id
}
}
}
into my graphiql editor I got the following error, Field "variants" is not defined by type "ProductInput".
Can you help me to fix this issue, I am not able to set my product price when created using graphql apii.
A big thanks!
It never occured to me to run a varian query on products that don't have variants(theoretically), this is the id i was looking for and i will itirate over the products to get that id with code.
side question,
Is there any way to see this id torugh the gui as well?
Like with the product it will be in the uri, but thats the product id, if there is an actual variant, again its in the uri when you go into the variant, but is there a way to see the id of the default variant number in the gui?