Add A Metaobject Entry To A Product Metafield (Type: List.Metaobject_reference)

Solved

Add A Metaobject Entry To A Product Metafield (Type: List.Metaobject_reference)

arieswen415
Shopify Partner
21 5 3

Hi Shopify community,

 

I would like to write a small program to update one of the Metafields of my products, but I am not sure what I did wrong to the query. The type of the Metafield is a list of Metaobject reference, and I am trying to add an entry to the Metafield.

 

Here is my query:

mutation {
  productUpdate(input: {
    id: "gid://shopify/Product/123456",
    metafields: [
      {
        id: "gid://shopify/Metafield/112233",
        value: "[\"gid://shopify/Metaobject/123123\"]",
      }
    ]
  }) {
    product {
      metafield(namespace: "custom", key: "content_block") {
        value
      }
    }
  }
}

With this query, I am assuming it will replace the current entries that the Metafield has, and update the Metafield with gid://shopify/Metaobject/123123, but nothing happens after I hit execute.

 

Is the query structure correct? Or is it caused by entering the wrong gids?

 

Any input is appreciated! Thank you in advance

Accepted Solution (1)

Liam
Community Manager
3108 341 879

This is an accepted solution.

Hi Arieswen415,

 

The mutation structure seems to be correct for updating a product's metafield. However, there are a couple of things you might want to check:

  1. Ensure the gid's you're using are correct and valid. You should be able to retrieve the specific product or metafield using these gid's in a GraphQL query. If you're not able to retrieve them, then it's likely they are incorrect, and that's what's causing this issue.

  2. Make sure that the metafield you're trying to update is not a private metafield. Private metafields are not accessible through the productUpdate mutation and require a different approach.

  3. Your value is a string representation of a list, which might not be what the metafield expects. If the metafield is set to accept a list of Metaobject references, you might need to provide the value a different format.

  4. Check the API version you're using. Some features might not be available in older versions of the API.

  5. Ensure you have the necessary permissions to update the product and its metafields.

If none of these suggestions work, please provide any error messages you're receiving or further details about your implementation to help us narrow down the issue.

 

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

Reply 1 (1)

Liam
Community Manager
3108 341 879

This is an accepted solution.

Hi Arieswen415,

 

The mutation structure seems to be correct for updating a product's metafield. However, there are a couple of things you might want to check:

  1. Ensure the gid's you're using are correct and valid. You should be able to retrieve the specific product or metafield using these gid's in a GraphQL query. If you're not able to retrieve them, then it's likely they are incorrect, and that's what's causing this issue.

  2. Make sure that the metafield you're trying to update is not a private metafield. Private metafields are not accessible through the productUpdate mutation and require a different approach.

  3. Your value is a string representation of a list, which might not be what the metafield expects. If the metafield is set to accept a list of Metaobject references, you might need to provide the value a different format.

  4. Check the API version you're using. Some features might not be available in older versions of the API.

  5. Ensure you have the necessary permissions to update the product and its metafields.

If none of these suggestions work, please provide any error messages you're receiving or further details about your implementation to help us narrow down the issue.

 

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