Where can I get the ID value of metafileds when registering for the product?
{
“input”: {
“metafields”: [
{
“description”: “”,
“id”: ???,
“key”: “use1”,
“namespace”: “custom”,
“type”: “multi_line_text_field”,
“value”: “meta11111”
}
],
…
}
A user asks how to obtain the ID value for metafields when registering them for a product.
Solution provided:
How to retrieve existing metafield IDs:
Use the GraphQL API to query the metafields connection on the Product type. A code example demonstrates querying a product’s metafields (first 10) to retrieve their id and key values.
Status: Question answered with technical guidance and working code snippet.
Where can I get the ID value of metafileds when registering for the product?
{
“input”: {
“metafields”: [
{
“description”: “”,
“id”: ???,
“key”: “use1”,
“namespace”: “custom”,
“type”: “multi_line_text_field”,
“value”: “meta11111”
}
],
…
}
Hi Weap0n7,
If you’re creating a new metafield for a product, you don’t need to provide an id value as this will be generated by Shopify once the metafield is created. However, if you are updating or retrieving an existing metafield, you would need the id value to reference the correct metafield.
To get the id values of existing metafields for a product, use the metafields connection on the Product type via the GraphQL API:
{
product(id: "gid://shopify/Product/1234567890") {
metafields(first: 10) {
edges {
node {
id
key
}
}
}
}
}
Hope this helps!