Solved

Product Update GraphQL Cannot Add Tags

TravisImagine
Shopify Partner
15 0 2

Hello,

 

I am currently using the product update GraphQL endpoint to change the tags on a product. Since the product was created some tags have either been changed, removed or added but there is no change to the product's tags. Using the input below, if I have keyword 1 and keyword 2, when I update the product, Keyword 3 is not added.

 

{
  "input": {
    "id": "gid://shopify/Product/123",
    "handle": "123",
    "tags": [
      "Keyword 1",
      "Keyword 2",
      "Keyword 3"
    ],
  }
}

If I delete and recreate the product, the tags are properly updated.

 

Can tags be modified after creating a product? If so, what is the correct way of doing it?

 

Thank you,

Travis

Accepted Solution (1)

Liam
Shopify Staff
2731 302 777

This is an accepted solution.

Hi Travis,

 

It is for sure possible to use the GraphQL API to change product tags after a product is created, with the productUpdate mutation that can access the `tags` field

 

After sending the mutation, check the response from the GraphQL API. If there's an error in the mutation, the response will typically contain error messages that can provide insights into what went wrong. 

 

When you update tags using the productUpdate mutation, the tags you provide will replace the existing tags. If you want to add or remove specific tags without affecting the existing ones, you'll need to first fetch the current tags, modify the list as needed, and then send the updated list in the productUpdate mutation.

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

Liam
Shopify Staff
2731 302 777

This is an accepted solution.

Hi Travis,

 

It is for sure possible to use the GraphQL API to change product tags after a product is created, with the productUpdate mutation that can access the `tags` field

 

After sending the mutation, check the response from the GraphQL API. If there's an error in the mutation, the response will typically contain error messages that can provide insights into what went wrong. 

 

When you update tags using the productUpdate mutation, the tags you provide will replace the existing tags. If you want to add or remove specific tags without affecting the existing ones, you'll need to first fetch the current tags, modify the list as needed, and then send the updated list in the productUpdate mutation.

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

TravisImagine
Shopify Partner
15 0 2

Hey Liam,

 

Thanks for the advice. Usually my updates were failing completely, and not returning anything at all. Looks like I was messing something else up in the mutation.

 

Thank you!