Weather Conditions


#1

I am wanting to be able to get the Weather Conditions via XML3 results to a JSON using php how ever when using the code below it returns null. IF in one can point me in the right direction please do :).

<?php require_once 'vendor/autoload.php'; use GuzzleHttp\Client; /* * This script will query FlightXML WeatherConditions and return a list of the * next 5 flights arrived/departed/scheduled/enroute. It expects the query parameter * airport_code to be set. * * It uses the guzzle http client to make the request from FlightXML. */ if (!$_GET['airport_code']) { echo json_encode(array('error' => 'Missing airport_code in request')); return; } $airport_code = $_GET['airport_code']; // Your FlightXML username/password $auth_info = [ 'user', 'pass' ]; // Create the base client - add whatever defauls you need here. $client = new Client([ 'base_uri' => 'http://flightxml.flightaware.com/json/FlightXML3/', 'auth' => $auth_info ]); // Query WeatherConditions $queryParams = [ 'airport_code' => $airport_code, ]; $fxml_response = $client->request('GET', 'WeatherConditions', ['query' => $queryParams]); try { $body = json_decode($fxml_response->getBody(), true); if ($fxml_response->getStatusCode() == 200 && !array_key_exists('error', $body)) { foreach (['conditions', 'clouds'] as $board) { if($body['WeatherConditionsResult'][$board]) { $boardFlights = $body['WeatherConditionsResult'][$board]['conditions']; $response[$board] = $boardFlights; } } } else { $response['error'] = $body['error']; } } catch (Exception $e) { echo json_encode(['error' => 'Failed to retrieve Airport Board details.']); } // Send back the data header('Content-Type: application/json'); echo json_encode($response);

#2

It looks like the request is correct, but the response parsing needs to be re-examined. It looks like there’s two values attempted.

WeatherConditionsResult -> cloud -> conditions - this isn’t a valid field type.
WeatherConditionsResult -> conditions -> conditions - this field may be empty if there is no notable weather condition.

Both of these can result in an empty response being returned from your backend application, even if a valid FlightXML response is present.