Hi
I have a script to import products and add MetaField on product with “REMOTE_PRODUCT_ID” for connect Shopify product with my remote product, this work.
But when i want check if product exist have this.
const { admin, session } = await shopify.authenticate.admin(request);
const exist_product = await admin.rest.resources.Metafield.all({
session: session,
limit: 1,
metafield: {namespace: "MY_NAME_SPACE", owner_resource: "product", key: "RELATIONAL_PRODUCT_ID"}
});
The metafield stored with namespace and this show success on product.
The const exist_product is a MetaField from “test_data” namespace
Exist product [
Metafield {
id: xxxxxxxxxx,
namespace: 'test_data',
key: 'alpine_sports',
value: '["snowboarding"]',
description: null,
owner_id: xxxxx,
created_at: '2024-04-03T07:05:40-04:00',
updated_at: '2024-04-03T07:05:40-04:00',
owner_resource: 'shop',
type: 'list.single_line_text_field',
admin_graphql_api_id: 'gid://shopify/Metafield/xxxxxxxxxxx'
}
]
If change my code to
const { admin, session } = await shopify.authenticate.admin(request);
const exist_product = await admin.rest.resources.Metafield.all({
session: session,
limit: 1,
namespace: "MY_NAME_SPACE",
metafield: { owner_resource: "product", key: "RELATIONAL_PRODUCT_ID"}
});
This response is empty, but i can see MetaField on my product.
Resume: I want check if product exist by MetaField (key and value). What am I doing wrong?
Thanks!