Hi,
I am using same code to get product list and to add metafields to the shop, but cant seem to get the correct incantation to add to product variants…
my code:
var record = {
key: key,
value: 1,
value_type: "integer",
namespace: "sale_class",
owner_resource: 'variants',
owner_id: variantId
}
await shopify.metafield
.create(record)
.then(metafield => {
logIt(" metafield.create() response:\n" + stringify(metafield));
}, err => {
logIt(" metafield.create() ERROR:\n" + stringify(err));
});
The response:
{ key: ‘Wholesale’,
value: 1,
value_type: ‘integer’,
namespace: ‘sale_class’,
owner_resource: ‘variants’,
owner_id: 16207071608866 }
metafield.create() ERROR:
{
name: “HTTPError”,
host: undefined,
hostname: “case-size-selector-development-store.myshopify.com”,
method: “POST”,
path: “/admin/metafields.json”,
protocol: “https:”,
url: undefined,
statusCode: 400,
statusMessage: “Bad Request”,
headers: {
server: “nginx”,
date: “Wed, 10 Apr 2019 06:46:05 GMT”,
“content-type”: “application/json; charset=utf-8”,
“transfer-encoding”: “chunked”,
connection: “close”,
“x-sorting-hat-podid”: “33”,
“x-sorting-hat-shopid”: “4983586850”,
“referrer-policy”: “origin-when-cross-origin”,
“x-frame-options”: “DENY”,
“x-shopid”: “4983586850”,
“x-shardid”: “33”,
“x-stats-userid”: “26989658146”,
“x-stats-apiclientid”: “2785525”,
“x-stats-apipermissionid”: “86388211746”,
http_x_shopify_shop_api_call_limit: “3/40”,
“x-shopify-shop-api-call-limit”: “3/40”,
“strict-transport-security”: “max-age=7889238”,
“x-request-id”: “e5b798a1-e793-4f14-a6d9-0ef8be26bc58”,
“x-shopify-stage”: “production”,
“content-security-policy”: “default-src ‘self’ data: blob: ‘unsafe-inline’ ‘unsafe-eval’ https://* shopify-pos://; block-all-mixed-content; child-src ‘self’ https:// shopify-pos://; connect-src ‘self’ wss:// https://*; frame-ancestors ‘none’; img-src ‘self’ data: blob: https:; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com ‘self’ ‘unsafe-inline’ ‘unsafe-eval’; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fmetafields&source%5Bsection%5D=admin_api&source%5Buuid%5D=e5b798a1-e793-4f14-a6d9-0ef8be26bc58”,
“x-content-type-options”: “nosniff”,
“x-download-options”: “noopen”,
“x-permitted-cross-domain-policies”: “none”,
“x-xss-protection”: “1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fmetafields&source%5Bsection%5D=admin_api&source%5Buuid%5D=e5b798a1-e793-4f14-a6d9-0ef8be26bc58”,
“x-dc”: “chi2,gcp-us-central1”
}