Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hello, so I created some metafields and have retrieved the ids for them successfully
query {metafieldDefinitions(ownerType: PRODUCT, first:10) {nodes {idkey}}}{"id": "gid://shopify/MetafieldDefinition/XXXXXXXXX","key": "category"},{"id": "gid://shopify/MetafieldDefinition/YYYYYYYYYY","key": "subcategory"}
mutation productUpdate($input: ProductInput!) {productUpdate(input: $input) {product {idmetafields(first: 10) {edges {node {namespacekeyvalue}}}}userErrors {fieldmessage}}}{"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"]}]
@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: