Admin API call redirection issue

Topic summary

Admin attempts to fetch product details (including metafields) for items in the cart using frontend JavaScript, but encounters 301 (permanent) redirects.

  • Approach: Calls Shopify AJAX API at /cart.js to list cart items, then requests Admin API endpoint /admin/api/2023-01/products/{product_id}.json for each item.
  • Observed issue: Network shows 301 redirects. The author believes the cause is domain mismatch—requests go to the .myshopify.com domain while the store’s primary domain is a custom domain (e.g., furnace.ca), triggering redirection.
  • Technical context: cart.js is part of Shopify’s AJAX API for retrieving cart data. A 301 indicates a permanent redirect to another URL/domain. Admin API is versioned (2023-01) and the code snippet is central to understanding the problem.
  • Status: No solutions or workarounds provided in the thread. The author is seeking guidance on handling domain redirection. Discussion remains open with unanswered questions.
Summarized with AI on January 30. AI used: gpt-5.

Hi I want to fetch the products that exist in cart for that I am using Js code that checks all the products added in crt page

fetch(‘/cart.js’)
.then(response => response.json())
.then(cart => {
// Loop through each item in the cart
cart.items.forEach(item => {
// Get the product information from Shopify’s AJAX API
fetch(/admin/api/2023-01/products/${item.product_id}.json)
.then(response => response.json())
.then(product => {
// Log the product’s metafields to the console
console.log(product);
});
});
});

I am using this code but this code gives me 301 redirect error.
The reason I found is that cart.js request send to .myshopify.com domain that is now not primary domain . My original domain is for example furnace.ca that’s why it gives me 301 redirect in response in developer network tab .

Can anyone have solution to this issue . Problem is related to domain redirection
Thanks