# RegisterAlertEndpoint example

**URL:** https://discussions.flightaware.com/t/registeralertendpoint-example/17203
**Category:** AeroAPI
**Created:** [August 20, 2015, 3:51pm UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203 "2015-08-20T15:51:45Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![airgrubsystems](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@airgrubsystems](https://discussions.flightaware.com/u/airgrubsystems)
#### Post date: [August 20, 2015, 3:51pm UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/1 "2015-08-20T15:51:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)
#### Post date: [August 20, 2015, 10:18pm UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/2 "2015-08-20T22:18:01Z")

</div>

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](https://flightaware.com/commercial/flightxml/key)

---

<div class="post-metadata">

### Author: ![airgrubsystems](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@airgrubsystems](https://discussions.flightaware.com/u/airgrubsystems)
#### Post date: [August 21, 2015, 6:20am UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/3 "2015-08-21T06:20:52Z")

</div>

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](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](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

---

<div class="post-metadata">

### Author: ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)
#### Post date: [August 21, 2015, 6:54am UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/4 "2015-08-21T06:54:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![airgrubsystems](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@airgrubsystems](https://discussions.flightaware.com/u/airgrubsystems)
#### Post date: [August 22, 2015, 6:41am UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/5 "2015-08-22T06:41:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![airgrubsystems](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@airgrubsystems](https://discussions.flightaware.com/u/airgrubsystems)
#### Post date: [August 24, 2015, 10:16pm UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/6 "2015-08-24T22:16:39Z")

</div>

I get back in the alert:

{“user\_id”:“3276”}

How do I get the flight update data from this?

---

<div class="post-metadata">

### Author: ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)
#### Post date: [August 25, 2015, 3:45pm UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/7 "2015-08-25T15:45:11Z")

</div>

> [@airgrubsystems](#):
>
> When the alert is triggered what does the post data look like? Is there any way for me to trigger test alerts?

For an example of what the Pushed Notification payload looks like, please see our documentation at [flightaware.com/commercial/flig … ation2.rvt](https://flightaware.com/commercial/flightxml/documentation2.rvt)

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

```auto

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

```

---

<div class="post-metadata">

### Author: ![airgrubsystems](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@airgrubsystems](https://discussions.flightaware.com/u/airgrubsystems)
#### Post date: [August 25, 2015, 5:02pm UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/8 "2015-08-25T17:02:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![bovineone](https://sea1.discourse-cdn.com/flex019/user_avatar/discussions.flightaware.com/bovineone/32/117631_2.png) [@bovineone](https://discussions.flightaware.com/u/bovineone)
#### Post date: [August 25, 2015, 6:47pm UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/9 "2015-08-25T18:47:54Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![airgrubsystems](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@airgrubsystems](https://discussions.flightaware.com/u/airgrubsystems)
#### Post date: [August 25, 2015, 7:13pm UTC](https://discussions.flightaware.com/t/registeralertendpoint-example/17203/10 "2015-08-25T19:13:13Z")

</div>

Didn’t see it, thanks!
