Solved

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

thearchitect
Excursionist
40 3 14

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
15846 2371 3074

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,

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Custom Pricing Wholesale App : Free | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing

View solution in original post

Replies 3 (3)

oscprofessional
Shopify Partner
15846 2371 3074

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,

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Custom Pricing Wholesale App : Free | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing
oscprofessional
Shopify Partner
15846 2371 3074

@thearchitect ,

Query to Update Product Price...

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

 

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Custom Pricing Wholesale App : Free | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing
thearchitect
Excursionist
40 3 14

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?