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.

How to update product price with graphQL if there is no variant

Solved

How to update product price with graphQL if there is no variant

thearchitect
Excursionist
40 3 15

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

Accepted Solution (1)

oscprofessional
Shopify Partner
16386 2441 3190

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,

Hire us | Pass Core Web Vital | B2B Wholesale Experts | Claim Your Free Website Review |
Connect with Us: WhatsApp | Skype: oscprofessionals-87 | Email: pallavi@oscprofessionals.com |
Custom Shopify SolutionsPrivate Apps, Theme Customization & SEO | Digital Marketing |
OSCP Apps: Discount Suite | Wholesale App | Bundle & Upsell | Shipping Discount | and more...

View solution in original post

Replies 4 (4)

oscprofessional
Shopify Partner
16386 2441 3190

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,

Hire us | Pass Core Web Vital | B2B Wholesale Experts | Claim Your Free Website Review |
Connect with Us: WhatsApp | Skype: oscprofessionals-87 | Email: pallavi@oscprofessionals.com |
Custom Shopify SolutionsPrivate Apps, Theme Customization & SEO | Digital Marketing |
OSCP Apps: Discount Suite | Wholesale App | Bundle & Upsell | Shipping Discount | and more...
oscprofessional
Shopify Partner
16386 2441 3190

@thearchitect ,

Query to Update Product Price...

mutation {
  productUpdate(input: {id: "gid://shopify/Product/8148348436784",
    variants:{
      price:300.00
    }
  }) {
    product {
      id
    }
  }
} 

 

Hire us | Pass Core Web Vital | B2B Wholesale Experts | Claim Your Free Website Review |
Connect with Us: WhatsApp | Skype: oscprofessionals-87 | Email: pallavi@oscprofessionals.com |
Custom Shopify SolutionsPrivate Apps, Theme Customization & SEO | Digital Marketing |
OSCP Apps: Discount Suite | Wholesale App | Bundle & Upsell | Shipping Discount | and more...
shivendra8004
Shopify Partner
5 0 0

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.

thearchitect
Excursionist
40 3 15

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?