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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Product variant price update with Graphql using javascript fetch

Product variant price update with Graphql using javascript fetch

abdurrakib528
Shopify Partner
10 0 6

Hello Expert,

I have faced a problem when updating product prices using Graphql in js fetch API.

 I can get all products but could not update the product price using Graphql mutation.

 

Errors: message"Field 'productVariantUpdate' doesn't exist on type 'Mutation'"

 

 

    const priceUpdate =` mutation {
            productVariantUpdate(input:{id:"gid://shopify/ProductVariant/40524123832528", price: "10"}) {
                                       productVariant {
                                        price
                                      }
                                    }
                                  }`
 const GRAPHQL_URL = 'https://dimerc-pmg.myshopify.com/api/2022-04/graphql.json';
              const GRAPHQL_BODY  = () => {
                return {
                  'async': true,
                  'crossDomain': true,
                  'method': 'POST',
                  'headers': {
                    'X-Shopify-Storefront-Access-Token': STOREFRONT_ACCESS_TOKEN,
                    'Content-Type': 'application/graphql',
                  },
                  'body': priceUpdate
                };
              }

              fetch(GRAPHQL_URL, GRAPHQL_BODY())
              .then(res => res.json())
              .then(products => {
                console.log('products', products)
              })

 

 

 

 

 The above is what I did for updating the price. Could you please help me with how can I achieve the perfect result?

 

Thanks in advance!

Replies 0 (0)