PHP Example


I’m restricted at the moment to demo retrieving AirVantage data using PHP. Does anybody have examples?

I’ve successfully used the av shell script to interact with AirVantage but converting the curl commands to PHP and JSON is proving slower than I’d like, not having done PHP before. I have managed to retrieve the access_token but subsequent curl queries are failing.

E.g. This request gets an error:


getAV({"error":"unauthorized","error_description":"Full authentication is required to access this resource"})

My curl function:

function getAV($url) {
        $curl = curl_init($url);   
        curl_setopt($curl, CURLOPT_HEADER, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');

        $postData = "";

        //This is needed to properly form post the credentials object
        foreach($params as $k => $v)
           $postData .= $k . '='.urlencode($v).'&';
                echo $postData;

        $postData = rtrim($postData, '&');

        curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);

        $data = curl_exec($curl);

        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

// evaluate for success response
        if ($status != 200) {
          throw new Exception("Error: call to URL $endpoint failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl) . "\n");
        $json = json_decode($data, true);

        return $json;

Browser output:

access_token => 77b32940-8624-457a-b9a7-936fa251cca2
token_type => Bearer
refresh_token => 03841f37-4e9a-486f-913a-d8913853b6ab
expires_in => 12785


Hi Steve,

First, yo ucan find more information about how to use API in this tutorial: … arted_api/

Another tutorial focused on PH is available here: … hp_sample/

Second, you may use postman or any Rest client to test your API call like described in this tutorial, it will be easier.

Your request is correct. Do you use the correct HTTP verb (GET) ?
This two lines seems root cause:

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/x-www-form-urlencoded');

You have to change to something like

curl_setopt($curl, CURLOPT_GET, true);
curl_setopt($curl, CURLOPT_HEADER,'Content-Type: application/json');



I’l still getting the “unauthorized” even with the json mod. I will review that area of the code more. My existing code did retrieve the access_token ok but subsequent calls were failing.

I did register with the AWS service but the link mentioned in the tutorial is no longer valid, so when I tried: … e.template

I got error:

<Message>All access to this object has been disabled</Message>


Hi Steve,

is just an example. You have to use the url which go on your AWS account and the stack you created using the previous step of this tutorial.
elasticbeanstalk-eu-west-1-281626357614: last number are different
Linux_Apache_PHP_AV4_Sample: if you followed the tutorial, you may have the same stack name.

If you get Unauthorized, get the url link is correct (http verb, no / at this end, typo, …).

Let me know if you have still an issue.


Hi Robert,

I eventually used file_get_contents(). Sierra Wireless also sent me the PHP code from the AWS server for reference but I’d already solved my initial issue. I tried various PHP curl techniques but none worked for me.

My proof of concept code lists some device properties:


$HOST = "";
$endpoint = $HOST."/api/oauth/token";

$json = file_get_contents('');
$obj = json_decode($json);

//echo $url;
$json = file_get_contents($url);
$o = json_decode($json);
//echo $json;
echo "Your Devices (name, UID & first label):<br>";

echo "<table width=60% border=1><tr><th>Device</th><th>Uid</th><th>Owner</th></tr>";
for ($i = 0; $i < $o->count; $i++) {
        echo "<tr>";
        echo "<td>". $o->items[$i]->type . "</td><td>" . $o->items[$i]->uid . "</td><td>". $o->items[$i]->labels[0] ."</td>";
        echo "</tr>";
echo "</table>";


Hi Steve,

I reworked the PHP Sample code to set it cleaner. I will update the page in November.

I send you the php file which works for me (after enabled session mgt in php.ini file) in private.