Metafield not showing up in javascript

metafield not showing up in javascript

API call used was
$out = $api->call(‘GET’, ‘/admin/products/798658789465/metafields.json’);

which is supposed to be a metafield for a product.

Metafields are not part of the product so if you do a dump like {{ product | json }} you won’t get them included. Always remember that Metafields are a resource that is linked to the product, but not part of it.

If you need to access them from with the theme code you will need do something like this in the template file:

let foo = {{ product.metafields.some-namespace.some-key | json }};

thanks for the reply

i just tried console.log(product.metafields.global.min_qty);

give undefined though API call

$out = $api->call(‘GET’, ‘/admin/products/798658789465/metafields.json’);

gives back:

[1] => Array
(
[id] => 3411923075161
[namespace] => global
[key] => min_qty
[value] => 1
[value_type] => integer
[description] =>
[owner_id] => 798658789465
[created_at] => 2018-07-03T09:29:32-04:00
[updated_at] => 2018-07-03T09:29:32-04:00
[owner_resource] => product
[admin_graphql_api_id] => gid://shopify/Metafield/3411923075161
)

should this be

let foo = {{products.product.metafields.namespace.value | json }};
?

Did you ever get this resolved? I would like more information on this