skip to Main Content

I am using a python script with requests to update various properties of a shopify shop using graphql and it works fine.

The problem is I can’t figure out how to update a product price when there is no product variant using Graphql

All the documentation refers to mutations on product variants, but most of the products on this shop don’t have any variants.

However I read somewhere that products without variants are "default variants" themselves, but i can’t find the id for this.

If I pass the product id, or global id, the response is just no id found.
I have spent hours on the documentation and I can’t find the correct reference.
I even asked our banned friend, but wasn’t really helpful:)

Here is the working graphql query for updating variants for reference.

query = '''
    mutation productVariantUpdate($input1: ProductVariantInput!) {
              item1: productVariantUpdate(input: $input1) {
                productVariant {
                  id,
                  price
                }
                userErrors {
                  field
                  message
                }
            }
    '''

variables = {
                "input2":{"id":"gid://shopify/ProductVariant/42177699971252","price":15.20}
            }

3

Answers


  1. Chosen as BEST ANSWER

    Ok, The confusing part was, when you have a product the uri has a product id, if you create a variant, there is a variant id in the uri as well. But i didn't realize that the existance of a default variant id as i never came across of this in the gui, so i never tried to run a variant query on a product without multiple variants.

    So running:

     {
      product(id: "gid://shopify/Product/123456798"){    
        variants(first:5 ){ 
          nodes {
            id
            price
          }
        }    
      }      
    }
    

    Does return the dafault variant id which i can then use for updating.


  2. A product has many variants. Between one, and one hundred. End of story. If you have a product ID, you can get the variant IDs. End of story. If you have a variant ID, you can get the variant details. With those, you will find that a variant has an inventory_item_id. Or inventoryItemId. You get the picture? With that, you can get the item! The item has a price. You can use a mutation to set the price. That is how it is done.

    If you say you have a product without a variant, that is false. Impossible.

    Login or Signup to reply.
  3. Sounds like you’re confusing the number of options with variants.

    The Product object also has a totalVariants count and hasOnlyDefaultVariant fields

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search