try { // Fetch the list of products const response = await fetch(url, { method: 'GET', headers: headers }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const responseBody = await response.json;
// Check if the response contains products if (!responseBody.products || !Array.isArray(responseBody.products)) { throw new Error("Invalid or missing response body from Shopify API"); }
// Find the product by title const product = responseBody.products.find(p => p.title.toLowerCase() === productTitle.toLowerCase());