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.

Unable to provide weight & weight_unit in ProductSet variations payload

Unable to provide weight & weight_unit in ProductSet variations payload

nadario
Shopify Partner
11 0 0

Since we are forced to migrate from an easy-to-understand REST API to the new GraphQL API, I could not figure out how to achieve the same product synchronization logic from "our" system into the Shopify store.

 

In the REST API, we could provide `weight` & `weight_unit` in the variations array along with a product. If I try to do the same with GraphQL's `ProductSet` mutation, I get the following error: 

Variable $entity11846 of type ProductSetInput! was provided invalid value for variants.0.weight (Field is not defined on ProductVariantSetInput)


(which makes sense, as the property is not available) https://shopify.dev/docs/api/admin-graphql/2024-10/mutations/productSet#argument-input => variations.

 

I have the following input payload:

 

 

 

 

{
  "title": "Lorem Ipsum Dolor Sit",
  "handle": "lorem-ipsum-dolor-sit",
  "descriptionHtml": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>",
  "productType": "Lorem, Ipsum, Dolor & Sit Amet",
  "files": [
    {
      "originalSource": "https://example.com/lorem-image-1.jpg",
      "contentType": "IMAGE"
    },
    {
      "originalSource": "https://example.com/lorem-image-2.jpg",
      "contentType": "IMAGE"
    }
  ],
  "variants": [
    {
      "price": 10.50,
      "optionValues": [
        {
          "optionName": "Lorem",
          "name": "Ipsum"
        }
      ]
    },
    {
      "price": 13.99,
      "optionValues": [
        {
          "optionName": "Dolor",
          "name": "Sit"
        }
      ]
    }
  ],
  "productOptions": [
    {
      "name": "Lorem",
      "position": 1,
      "values": [
        {
          "name": "Ipsum"
        }
      ]
    }
  ]
}

 

 

 

 

So how to achieve to add the weight and weight unit values into the variations payload?

Replies 9 (9)

LucaRaveri
Shopify Partner
20 3 7

Do you mean variants? You should update your post since variations doesn't exists.

However I checked the documentation and the measurement field which contains the weight is associated with the InventoryItem type.
Since the InventoryItem type isn't in ProductSetInput type i don't think you can update the weight using the ProductSet mutation.

Is this a bug? Idk, lemme know if you find a solution

If this was helpful, please Like it ⬆️
If this solved your problem, please Mark it as solution
nadario
Shopify Partner
11 0 0

Thanks for the Reply. Indeed its "variants" not "variations", sadly i am unable to update the post. 

Kyle_liu
Shopify Partner
386 50 66

@nadario 

 

This operation is no longer supported in productSet. You can use productVariantsBulkCreate to implement your business

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee
nadario
Shopify Partner
11 0 0

Thanks, @Kyle_liu , for the answer. At least now I am aware that I cannot use the ProductSet.

 

My two cents on this (knowing this is not your fault, @Kyle_liu , of course)

 

We have a sync process from our system into Shopify, and now using different strategies with different endpoints is a huge mess. The ProductSet was meant for migration (as far as I know). The ProductSet option is perfect for handling all these processes in bulk with similar behavior. Now, I have to manually update all variants for each product, just because of this. On a huge dataset, this is a real mess.

 

So if Shopify is forcing us to use the new GraphQL endpoints (I can understand such decisions technically), it should at least provide a similarly good experience for developers and not the opposite.

Kyle_liu
Shopify Partner
386 50 66

Yes, I agree with your point of view. Many people have complained about it.

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee
nadario
Shopify Partner
11 0 0

is there a road map for features? or is there any thread or feature request from other developers, without this feature we won't be able to migrate to the new graphql system. with all the rate limits and splitting up things in different requests, its almost impossible to correctly sync hundreds of products into shopify. 

Kyle_liu
Shopify Partner
386 50 66

You can try the steps:

productSet mutation to create or update the product

productOperation query to get the set operation and the product

productDeleteMedia to clean up old media (if it's an update)

productCreateMedia to aappend the new media

productVariantsBulkUpdate to set up inventory item for product variants

inventorySetQuantities to enable fulfillment inventory

publishablePublish to publish the product to the online store

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee
nadario
Shopify Partner
11 0 0

Thanks @Kyle_liu for taking time, i appreciate that a lot, very kind of you!

 

That's insane, its not possible to manage all those calls, there are also api rate limits to consider, this will never run stable when you have 100 of products. Sometimes your calls get rate limited then maybe an update call won't run anymore etc. Its a shame they don't provide a good migration path. We will wait until the hopefully add measurements to the ProductSet call - everything else is a mess.

nadario
Shopify Partner
11 0 0