FlightAware Discussions

FlightInfoStatus return no flights

Hi
I have test the FlightInfoStatus API with few flights like UAL0001//LH1340//UAL1//UA1//DLH1340
for all of them I got no flights so probably I’m doing something wrong.
here is the code
static void Main(string args)
{
string fxmlUrl = “http://flightxml.flightaware.com/json/FlightXML3”;
string username = “myusername”;
string apiKey = “myapiKey”;

        var uriBuilder = new UriBuilder(fxmlUrl);
        var requestUrl = fxmlUrl
                  .AppendPathSegment("FlightInfoStatus")
                  .SetQueryParams(new
                  {
                      ident = "UAL0001"//LH1340//UAL1//UA1//DLH1340
                        });

        ProcessRepositories(requestUrl, username, apiKey).Wait();
    }

    private static async Task ProcessRepositories(string apiUrl, string username, string apiKey)
    {
        var serializer = new DataContractJsonSerializer(typeof(ArrayOfFlightInfoStatusStruct));
        var client = new HttpClient();
        var credentials = Encoding.ASCII.GetBytes(username + ":" + apiKey);
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials));

        var streamTask = client.GetStreamAsync(apiUrl);
        //var airportInfo1 = serializer.ReadObject(await streamTask);

        var airportInfo = serializer.ReadObject(await streamTask) as ArrayOfFlightInfoStatusStruct;
        foreach (FlightInfoStatusStruct item in airportInfo.flights)
        {
            Console.WriteLine("actual_arrival_time - " + item.actual_arrival_time);
            Console.WriteLine("aircrafttype - " +item.aircrafttype);
            Console.WriteLine("actual_departure_time - " +item.actual_departure_time);

        }
    }

The query is valid and returning results. It’s likely that the returned object is not being parsed properly and the array of flight objects isn’t actually being iterated through. Here’s a barebones definition for the serializer that can help getting things started.

    [DataContract]
    class RootFlightInfoStatusObject
    {
        [DataMember(Name = "FlightInfoStatusResult")]
        public FlightInfoStatusResult FlightInfoStatusResult { get; set; }
    }

    [DataContract]
    class FlightInfoStatusResult
    {
        [DataMember(Name = "next_offset")]
        public int NextOffset { get; set; }
        [DataMember(Name = "flights")]
        public List<FlightInfoStatusStruct> Flights { get; set; }
    }

    [DataContract]
    public class FlightInfoStatusStruct
    {
        [DataMember(Name = "aircrafttype")]
        public string AircraftType { get; set; }
        [DataMember(Name = "actual_departure_time")]
        public Timestamp ADT { get; set; }
        [DataMember(Name = "actual_arrival_time")]
        public Timestamp AAT { get; set; }
    }

    [DataContract]
    public class Timestamp
    {
        [DataMember(Name = "epoch")]
        public int Epoch { get; set; }
    }