Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How do GET a specific variant metafield id?

Solved

How do GET a specific variant metafield id?

JaredUHS
Shopify Partner
1 0 0

I am looking to dynamically update product variant metafields, currently the flow in Celigo only allows for the variant metafield to be created, not updated.

After some digging I figured out how to update variant metafields, however, I need the variant metafield's ID.

I have come to the conclusion that I could just map the variant metafield ID of every product to their respective record in NetSuite, and use that id for the flow that updates the metafields.

The only issue I have is how do I get the specific variant metafield's ID and ignore the other ones?

 

In this case, I only want the variant metafield ID where the namespace is "dropship" and the key is "lead_time", so I want to get the ID '19962405978179'.

How can I do this for all our products?

 

Thanks!

 

{"metafields":[{"id":19812428513347,"namespace":"netsuite","key":"internal_id","value":29315,"description":null,"owner_id":39882427727939,"created_at":"2022-04-04T16:50:43-04:00","updated_at":"2022-04-04T16:50:43-04:00","owner_resource":"variant","type":"number_integer","admin_graphql_api_id":"gid:\/\/shopify\/Metafield\/19812428513347"},{"id":19925029716035,"namespace":"netsuite","key":"item_type","value":"Inventory Item","description":null,"owner_id":39882427727939,"created_at":"2022-05-17T17:22:50-04:00","updated_at":"2022-05-17T17:22:50-04:00","owner_resource":"variant","type":"single_line_text_field","admin_graphql_api_id":"gid:\/\/shopify\/Metafield\/19925029716035"},{"id":19941761351747,"namespace":"nets","key":"internal_id","value":29315,"description":null,"owner_id":39882427727939,"created_at":"2022-05-25T02:05:33-04:00","updated_at":"2022-05-25T02:05:33-04:00","owner_resource":"variant","type":"number_integer","admin_graphql_api_id":"gid:\/\/shopify\/Metafield\/19941761351747"},{"id":19942441680963,"namespace":"net","key":"item_type","value":"Inventory Item","description":null,"owner_id":39882427727939,"created_at":"2022-05-25T04:06:27-04:00","updated_at":"2022-05-25T04:06:27-04:00","owner_resource":"variant","type":"single_line_text_field","admin_graphql_api_id":"gid:\/\/shopify\/Metafield\/19942441680963"},{"id":19962405978179,"namespace":"dropship","key":"lead_time","value":1,"description":null,"owner_id":39882427727939,"created_at":"2022-06-02T10:52:32-04:00","updated_at":"2022-06-02T11:11:43-04:00","owner_resource":"variant","type":"number_integer","admin_graphql_api_id":"gid:\/\/shopify\/Metafield\/19962405978179"}]}

 

Accepted Solution (1)

francesco_gs
Shopify Partner
73 6 12

This is an accepted solution.

Hi there!

when calling the resource' metafields you can use query parameters to look for a specific metafield, while you can use the "fields" parameter to request in the output only certain fields, in your case the metafield ID

so like 
GET /products/{{product.id}}/metafields.json?namespace=dropship&key=lead_time&fields=id

This is easier of GraphQL where you can query a resource and ask for specific metafields

{

product(id:"gid://shopify/Product/{{product.id}}") {

metafield(namespace:"dropship", key:"lead_time") {

id

}

}

}

 

View solution in original post

Reply 1 (1)

francesco_gs
Shopify Partner
73 6 12

This is an accepted solution.

Hi there!

when calling the resource' metafields you can use query parameters to look for a specific metafield, while you can use the "fields" parameter to request in the output only certain fields, in your case the metafield ID

so like 
GET /products/{{product.id}}/metafields.json?namespace=dropship&key=lead_time&fields=id

This is easier of GraphQL where you can query a resource and ask for specific metafields

{

product(id:"gid://shopify/Product/{{product.id}}") {

metafield(namespace:"dropship", key:"lead_time") {

id

}

}

}