FlightXML / ASP / JSON - Search example code?


#1

Hello,
I am new to this API and am limited to using classic ASP for this website. The only example I found on your site is using the “Arrived” method - can you help send an example that returns a search result for all aircrafts in flight by model, but only for the various “Cessna” models ?
Any guidance on how to obtain the search results and parse through them would be very helpful.


postData = "airport=KCLT&filter=AircraftType"

Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open "POST", "http://flightxml.flightaware.com/json/FlightXML2/Arrived", False, "YOUR_USERNAME", "YOUR_APIKEY"
httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.Send "airport=KCLT&filter=airline"

If httpRequest.status = 200 Then
    Set jsonResponse = JSON.parse(httpRequest.responseText)

    For Each flight In jsonResponse.ArrivedResult.arrivals
       Response.Write("Flight " & flight.ident & " is arriving from " & flight.origin & "<br>") 
    Next
Else
    Response.Write("Error occurred")
End If

Set httpRequest = Nothing

Thanks,
Jason


#2

You should be able to do something like this:



Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open "POST", "http://flightxml.flightaware.com/json/FlightXML2/Search", False, "YOUR_USERNAME", "YOUR_APIKEY"
httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.Send "query=-type C1* -inAir 1"


(You may need to do some character escapement in the httpRequest.Send for the space characters.)

That will search for the aircraft type that begin with “C1” (such as C172, C182, C152, etc). Cessna’s model codes generally all begin with “C” followed by a number, however there are some non-Cessna models that begin with C (such as CRJ7, CL60, etc), so it’s a little difficult to create a single wildcard that will only return Cessna models. You can choose to repeat the above query for different “C1*”, “C2*”, “C3*” if you want to get all of the codes. Alternatively, you can use SearchBirdseyeInFlight and use “{aircraftType {C1* C2* C3* C4* C5* C6* C7* C8* C9*}}”, however be aware that function is a little more expensive to call.


#3

Thank you!

What is the proper XML object to extract the flight information on each of these from? I assume that I will not be using ArrivedResult.arrivals?

Current Logic:


    
For Each flight In jsonResponse.ArrivedResult.arrivals
       Response.Write("Flight " & flight.ident & " is arriving from " & flight.origin & "<br>") 
Next



#4

I think you’ll need to iterate over the array returned in jsonResponse.SearchResult.aircraft