May I know if it was possible to get the "productVariant metafields" by using Jquery Ajax and graphQL?
I am able to use the graphQL below to get the response object by using Python and Postman.
query {
productVariant(id: "gid://shopify/ProductVariant/11111111111111") {
metafields(first: 10) {
edges {
node {
namespace
key
value
}
}
}
}
}
However, I cannot apply it by using jquery. I try to put the code below in one of my template liquid files but return nothing.
----------------------------------------------------------
<script>
var settings = {
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "application/json"
},
"data": JSON.stringify({
query: "query {\r\n productVariant(id: \"gid://shopify/ProductVariant/1111111111111\") {\r\n metafields(first: 10) {\r\n edges {\r\n node {\r\n namespace\r\n key\r\n value\r\n }\r\n }\r\n }\r\n }\r\n}\r\n",
variables: {}
})
};
$.ajax(settings).done(function (response) {
alert(response);
});
</script>
----------------------------------------------------------------------
Beside ajax, I also try to use fetch. Unfortunately, both of their response is EMPTY.
Can anyone teach me how to make it work? Thanks a lot.