RegisterAlertEndpoint example


#1

I need a php example of the RegisterAlertEndpoint api. There is nothing in your forum or documentation. I tried to use SoapClient, but got this error:

SoapFault exception: [HTTP] Authorization Required

Even though I entered my username and password in the options object.

Thanks


#2

Try starting out with one of the existing PHP samples that invokes any other FlightXML function first. Diving deep into the more complex API is not the best strategy.

Additionally, I see that your username “airgrubsystems” does not have any FlightXML API keys generated yet, so if that is the account you are using for development then you first need to go to flightaware.com/commercial/flightxml/key


#3

Is this what registering an endpoint looks like? Where does the API key go?

$options = array(‘trace’ => true, ‘exceptions’ => 0, ‘login’ => ‘myusername’, ‘password’ => ‘mypassword’,);
$client = new SoapClient(‘http://flightxml.flightaware.com/soap/FlightXML2/wsdl’, $options);
$params = array(“format_type” => “json/post”, “address” => “http://” . $data’domain’] . “/api/v2/services/index.php?action=alertCallback”);
$result = $client->RegisterAlertEndpoint($params);

Is this what setAlert looks like? Again, where does the API key go?

$options = array(‘trace’ => true, ‘exceptions’ => 0, ‘login’ => ‘myusername’, ‘password’ => ‘mypassword’);
$client = new SoapClient(‘http://flightxml.flightaware.com/soap/FlightXML2/wsdl’, $options);
$params = array(“alert_id” => “”, “ident” => $data’flight_number’] . $data’airline_code’], “origin” => $data’departure_airport’], “destination” => $data’arrival_airport’], “aircrafttype” => “”, “date_start” => $data’order_timestamp’], “date_end” => $data’order_timestamp’], “channels” => “{16 e_filed e_departure e_arrival e_diverted e_cancelled}”, “enabled” => “”, “max_weekly” => “1000”);
$result = $client->SetAlert($params);

Why is this the response to both?

SoapFault exception: [HTTP] Authorization Required


#4

The API key is what you supply in the password argument for the $options array.


#5

When the alert is triggered what does the post data look like? Is there any way for me to trigger test alerts?


#6

I get back in the alert:

{“user_id”:“3276”}

How do I get the flight update data from this?


#7

For an example of what the Pushed Notification payload looks like, please see our documentation at flightaware.com/commercial/flig … ation2.rvt

When using PHP to implement the endpoint, you’ll want to be parsing the raw POST body using something like this:


$postdata = file_get_contents("php://input")


#8

There are no examples of the setAlert callback payload in the documentation. Can you post one here in the forum?


#9

Go to that page and click “Show example (JSON push notification)…” and there are 3 examples of the JSON output that is sent to you.


#10

Didn’t see it, thanks!