Best way to Add tags - not replace - using API?

Martijn_Spronk
Shopify Partner
9 0 3

I'm trying to programmatically add tags to products.

The only option I see would be using the /products/<#id>.json POST , but it seems this would replace the tags? Is that assumption correct?
Is there a better way to add tags to the existing list of tags?

Replies 3 (3)
Ashish_Lucent
Shopify Expert
35 0 3

Yes, It will replace tags, and no direct option to append tags,

But we generally use this way.

  • Read current tag of product using API
  • Append new tag
  • Replace tags through API
Shopify Plus Expert
https://experts.shopify.com/lucentinnovation
Ravipatel
Shopify Partner
32 0 2

Hello Ashish,

i agree with you but i know shopify provide less facilities can you provide any guidline so i can append some of tags using api

ex:- my product tag : category_saree,color_black,size_xxl etc...

and i want to append product tag : Catelog_latest-product,hot_products

but 1 thing without read current tag it's possibal?

 

tommydev
Excursionist
15 0 1

Dear Ravipatel,

 

with the REST API, I think it is not possible to keep the old tags while performing a PUT request. However I noticed, that it is possible by using the GraphQL API. There is a mutation to add tags: https://shopify.dev/api/admin-graphql/2021-10/mutations/tagsAdd and it kept the previous tags, when I execute it.

 

For example:

 

 

mutation tagsAdd {
  tagsAdd(id: "gid://shopify/Order/<your_order_id>", tags: "Test") {
    node {
      id
    }
    userErrors {
      field
      message
    }
  }
}

 

 

 

Greetings, Tom