function invokeGetRequest($requestUrl) { global $apiKey, $base_url, $source, $destination, $doj; // Construct URL with query parameters $queryParams = http_build_query([ 'source' => $source, 'destination' => $destination, 'doj' => $doj ]); $url = $base_url . $requestUrl . '?' . $queryParams; // Set up headers (API Key sent in a custom header) $headers = [ "Content-Type: application/json", "authorization: ApiKey $apiKey" ]; try { // Initialize cURL $ch = curl_init(); if (!$ch) { throw new Exception("cURL initialization failed"); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_TIMEOUT, 120); $response = curl_exec($ch); if ($response === false) { throw new Exception("cURL Error: " . curl_error($ch)); } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); // Return the response in the desired format return [ "status" => $httpCode, "response" => json_decode($response, true) ]; } catch (Exception $e) { // Handle the exception as needed (e.g., logging, rethrowing, etc.) echo "Request failed: " . $e->getMessage(); } }