volhon
1
I’m trying to get variantID using fetch:
fetch(`/admin/api/2022-04/products/${productID}/variants.json`, {mode: 'no-cors'})
.then(response => response.json())
but have this error: net::ERR_TOO_MANY_REDIRECTS
Is this some kind of limitation? or am I doing something wrong?
Hello @volhon ,
You can get variantID using below code
var productID = ‘6908699902091’; (Ex.)
var requestOptions = {
‘content-type’: ‘application/json’,
method: ‘GET’,
};
var shopName = window.Shopify.shop;
var productContents = fetch(https://${shopName}/admin/api/2022-04/products/${productID}/variants.json, requestOptions)
.then(response => response.json())
.then(data => { console.log(data.variants) });
Hopefully that helps.