"invalid id" error when trying to update product's metafields

Topic summary

A user successfully retrieved metafield definition IDs but encountered an \

Summarized with AI on November 9. AI used: claude-sonnet-4-5-20250929.

Hello, so I created some metafields and have retrieved the ids for them successfully

query {> metafieldDefinitions(ownerType: PRODUCT, first:10) {> nodes {> id> key> }> }> }> > {> “id”: “gid://shopify/MetafieldDefinition/XXXXXXXXX”,> “key”: “category”> },> {> “id”: “gid://shopify/MetafieldDefinition/YYYYYYYYYY”,> “key”: “subcategory”> }
But when I try to update them like below I get an error

mutation productUpdate($input: ProductInput!) {> productUpdate(input: $input) {> product {> id> metafields(first: 10) {> edges {> node {> namespace> key> value> }> }> }> }> userErrors {> field> message> }> }> }> > {> “input”: {> “id”: “gid://shopify/Product/ZZZZZZZZZZ”,> “metafields”: [{> “id”: “gid://shopify/MetafieldDefinition/XXXXXXXXX”,> “value”: “Exterior”> },> {> “id”: “gid://shopify/MetafieldDefinition/YYYYYYYYYY”,> “value”: “Bumpers”> }]> }> }> > “errors”: [> {> “message”: “invalid id”,> “locations”: [> {> “line”: 3,> “column”: 3> }> ],> “path”: [> “productUpdate”> ]> }> ]

any ideas why?

@Sprockets you are passing in the Metafield Definition Id which is not the correct id to pass. Each Product’s Metafield has a different metafield id for the metafield definition it is associated with.

You have to query the Product first and then pass the metafield id which is retrieved from the response of the query.

query {
  product(id: "gid://shopify/Product/1") {
    metafield(namespace: "instructions", key: "wash") {
      id # pass in this id value as your metafields id
      value
    }
  }
}

Docs:

1. Query the product

2. Update the product