Yes, I am passing a auth token in header X-Shopify-Access-Token : token.
I used my updated auth token always because I used it from the shopify app bridge session.
here is my code for detail
const handleshopifyRequest = async (type, url, token, body) => {
try {
let options = {
method: type,
url: url,
json: true,
body: body,
resolveWithFullResponse: true, //added this to view status code
headers: {
"X-Shopify-Access-Token": token,
"content-type": "application/json",
},
};
return request(options);
} catch (err) {
throw err;
}
};
const updateMetafieldPremium = async (userData, value) => {
try {
let metafieldPayload = {
metafield: {
namespace: "tt_schema",
key: "tt_schema_premium",
value: value,
type: "boolean",
owner_resource: "shop",
},
};
console.log(metafieldPayload, "Metafield Payload");
console.log(
"https://rewmar@" +
userData.shopUrl +
"/admin/api/" +
process.env.SHOPIFY_API_VERSION +
"/metafields.json",
"URLURLURLURLURL",
userData.accessToken,
"Access Token"
);
if (userData.metafield && userData.metafield.id) {
return await handleshopifyRequest(
"put",
"https://" +
userData.shopUrl +
"/admin/api/" +
process.env.SHOPIFY_API_VERSION +
"/metafields/" +
userData.metafield.id +
".json",
userData.accessToken,
metafieldPayload
);
} else {
return await handleshopifyRequest(
"post",
"https://" +
userData.shopUrl +
"/admin/api/" +
process.env.SHOPIFY_API_VERSION +
"/metafields.json",
userData.accessToken,
metafieldPayload
);
}
} catch (error) {
console.log("error-=-=-=-=-=-=", error.error);
throw error;
}
};
So in this my console log is completely fine! and If I take this console log URL and access token and try to create metafields from postman it is working correctly. however it is not working in my code only which I’ve provided.