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

Challenge with productUpdate in Admin API (GraphQL) adding Tags to Product

Solved

Challenge with productUpdate in Admin API (GraphQL) adding Tags to Product

RobinKZ
Shopify Partner
7 1 0

Hi, I'm trying to add some tags to a product via productUpdate and I'm running into the problem that no matter what I pass is doesn't fail but the tags are not updated.

 

I'm sending this:

mutation {
    productUpdate(input: {
      id: "gid://shopify/Product/${id}", 
      title: "${data.title}", 
      descriptionHtml: "${data.descriptionHtml}",      
      metafields: [{
        key: "mainmaterial",
        namespace: "my_fields",
        value: "${data.metafields.mainmaterial}"
      }],
      tags: ["Hest","Fisk"]
    }) {
      product {
        id
        descriptionHtml
        images(first:50) {
          edges {
            node {
              id
              src
            }
          }
        }
        tags
        metafields(first:10) {
          edges {
            node {
              namespace
              key
              value
            }
          }
        }
      }
    }
  }

And I'm getting this in return:

{
  id: 'gid://shopify/Product/7214229487809',
  descriptionHtml: '...',
  images: {
    edges: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ]
  },
  tags: [],
  metafields: { edges: [ [Object] ] }
}

As you can see "tags" returns blank and I've confirmed in the admin section on the product that no tags have been added.

 

I've tried:

tags: ["Tag1, Tag2, Tag3"]

tags: ["Tag1","Tag2","Tag4"]

tags: "Tag1, Tag2, Tag3"

tags: "[\"Tag1\", \"Tag2\", \"Tag3\"]"

 

Nothing seems to take and I don't get any error messages, except for the bottom one.

 

Any help is appreciated.

Accepted Solution (1)

RobinKZ
Shopify Partner
7 1 0

This is an accepted solution.

Problem was related to Metafields and not tags at all. The problem was I was not passing the ID of the metafield so it thought I wanted to create the same metafield over and over again, instead of getting an error message it just ignores updating the entire object.

View solution in original post

Reply 1 (1)

RobinKZ
Shopify Partner
7 1 0

This is an accepted solution.

Problem was related to Metafields and not tags at all. The problem was I was not passing the ID of the metafield so it thought I wanted to create the same metafield over and over again, instead of getting an error message it just ignores updating the entire object.