ProductSet and existing global metafield

Hi

I believe I found a bug in updating a metafield with the namespace global using the productSet mutation.

If the product is being created, there’s no issue—the created product has the metafield correctly set.
However, if I try to update it with the following data, I generally get the error:
“Key must be unique within this namespace on this resource”

{
    "gid": "gid://shopify/Metafield/...",
    "key": "title_tag",
    "namespace": "global",
    "type": "single_line_text_field",
    "value": "My super title"
}

If I perform the same operation with a non-global metafield, there are no issues.

Could you please provide the API details used to update the product metafield?

Hi @AMaL

To replicate the situation, I created the product with ProductSet without specifying the global metafield, then I modified the product’s SEO title from the Web. Subsequently, I constructed this call, which was supposed to update the product with all its fields, including the global metafield.

{
    "input": {
        "descriptionHtml": "yessa",
        "files": [
            {
                "duplicateResolutionMode": "APPEND_UUID",
                "id": "gid://shopify/MediaImage/28804688478398"
            },
            {
                "duplicateResolutionMode": "APPEND_UUID",
                "id": "gid://shopify/MediaImage/28804688511166"
            }
        ],
        "id": "gid://shopify/Product/8367631958206",
        "metafields": [
            {
                "key": "brand",
                "namespace": "custom",
                "type": "single_line_text_field",
                "value": "My Brand"
            },
            {
                "id": "gid://shopify/Metafield/42168478433470",
                "key": "title_tag",
                "namespace": "global",
                "type": "single_line_text_field",
                "value": "My super Title"
            }
        ],
        "productOptions": [
            {
                "name": "Title",
                "values": [
                    {
                        "name": "variante 2"
                    },
                    {
                        "name": "variante 1"
                    }
                ]
            }
        ],
        "productType": "Snowboard",
        "status": "ACTIVE",
        "tags": [],
        "title": "My super Product",
        "variants": [
            {
                "barcode": "8000000004734",
                "compareAtPrice": "9.00",
                "file": {
                    "duplicateResolutionMode": "APPEND_UUID",
                    "id": "gid://shopify/MediaImage/28804688478398"
                },
                "id": "gid://shopify/ProductVariant/44697790939326",
                "inventoryPolicy": "CONTINUE",
                "optionValues": [
                    {
                        "name": "variante 1",
                        "optionName": "Title"
                    }
                ],
                "price": "6.00",
                "sku": "8000000004734"
            },
            {
                "barcode": "8000000004735",
                "compareAtPrice": "5.00",
                "file": {
                    "duplicateResolutionMode": "APPEND_UUID",
                    "id": "gid://shopify/MediaImage/28804688511166"
                },
                "id": "gid://shopify/ProductVariant/44697790972094",
                "inventoryPolicy": "DENY",
                "optionValues": [
                    {
                        "name": "variante 2",
                        "optionName": "Title"
                    }
                ],
                "price": "6.00",
                "sku": "8000000004735"
            }
        ],
        "vendor": "My Vendor"
    },
    "synchronous": true
}

Best regards.

The metafields key title_tag and description_tag are used to set the SEO meta title tag and description.

To update these metafields, please use the product update query:

mutation {
  productUpdate(
    input: {
      id: "gid://shopify/Product/5591484858390"
      metafields: [
        {
          id: "gid://shopify/Metafield/21111411048611",
          value: "Matte black sunglasses"
        }
      ]
    }
  ) {
    product {
      metafields(first: 10) {
        edges {
          node {
            key
            value
          }
        }
      }
    }
  }
}

Alternatively, if you want to create/update using the product set query, use the seo field in the product set query:

mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) {
  productSet(synchronous: $synchronous, input: $productSet) {
    product {
      id
    }
    productSetOperation {
      id
      status
      userErrors {
        code
        field
        message
      }
    }
    userErrors {
      code
      field
      message
    }
  }
}

Variables:

{
  "productSet": {
    "id": "gid://shopify/Product/7851971248188",
    "seo": {
      "title": "The Demo product",
      "description": "The product is a test product"
    },
    "metafields": [
      {
        "key": "brand",
        "namespace": "custome",
        "type": "single_line_text_field",
        "value": "My Brand"
      }
    ]
  },
  "synchronous": true
}

Could you please try this query?

I understand the problem: productSet allows me to create the product with title_tag and description_tag, but not to update them, and in general, it’s always better to use the dedicated SEO section. Thanks for the advice.