1, $phone_field => $login_phone, $pin_field => $login_pin ]; curl_setopt($ch, CURLOPT_URL, $login_url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); if ($use_json_payload) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($login_data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); } else { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($login_data)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']); } $login_response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code !== 200) { return ['error' => "Login POST failed with HTTP $http_code. Response: " . substr($login_response, 0, 500)]; } $login_data = json_decode($login_response, true); if (!$login_data) { return ['error' => "Login response is not valid JSON: " . substr($login_response, 0, 500)]; } // Extract token from the response structure $token = $login_data['data']['token'] ?? null; if (!$token) { $debug = "Keys in top-level: " . implode(', ', array_keys($login_data)); if (isset($login_data['data'])) { $debug .= " | data keys: " . implode(', ', array_keys($login_data['data'])); } return ['error' => "No token found. $debug. Full response: " . substr($login_response, 0, 500)]; } // --- FETCH PRODUCTS using Bearer token --- curl_setopt($ch, CURLOPT_URL, $products_url); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer ' . $token, 'Content-Type: application/json', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36' ]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $json_data = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($http_code !== 200) { return ['error' => "Failed to fetch products: HTTP $http_code. Response: " . substr($json_data, 0, 500)]; } // Validate JSON $decoded = json_decode($json_data, true); if ($decoded === null) { return ['error' => "Invalid JSON from products endpoint: " . substr($json_data, 0, 500)]; } return ['success' => true, 'data' => $json_data]; } // ------------------------------------------------------------------- $fetch_result = fetchProducts($login_url, $login_phone, $login_pin, $products_url, $phone_field, $pin_field, $pwa_field, $use_json_payload); if (isset($fetch_result['error'])) { $hasData = false; if (file_exists($json_file)) { $content = file_get_contents($json_file); $json = json_decode($content, true); if (!empty($json['data'])) { $hasData = true; } } } else { file_put_contents($json_file, $fetch_result['data']); $hasData = true; } ?> Tupperware Products

Loading...

⚠️ Could not fetch products

Current settings:

Try products.php anyway