How do I remove product category via productUpdate graphql mutation?

hey everyone!

how do i delete a product category in the product update graphl mutation? updating to a diff category is done by providing the taxonomy node id, but unable to remove an existing product category as cant provide nil. please could you share how to do this?

for example, i can update the product category by providing these inputs to the productUpdate mutation

{
  "input": {
    "id": "gid://shopify/Product/8535186833687",
  	"title": "news",
    "productCategory": {
      "productTaxonomyNodeId": "gid://shopify/ProductTaxonomyNode/3522"
    }
  }
}

This works correctly - but now how do I remove a product category and make it nil. Tried providing nil and an empty hash to productCategory, but get back this error

"Variable $input of type ProductInput! was provided invalid value for productCategory.productTaxonomyNodeId (Invalid global id '')"

Just wondering how to fix this.

Thank you!

Arjun

1 Like

Hi @arjun_rajkumar

The productCategory is a nullable field on the Product object so you should be able to remove it by providing a null value in the productUpdate mutation. This is what it looks like on my test store:

Hope that helps.

1 Like