Context APIs

Context data allows to gather precious context information aobut the user, the location and access points where he is connecting and about the Cloud4Wi Org the user belongs to.


There are two ways to retrive the Context data:

  • Context APIs
  • Javascript SDK


Using Context APIs

Making a GET request to the API url with the session key appended will return with a json object depending on the context with which the API was called. For example, calling the API from the Admin Panel will return different results than calling it from within the access journey.


The API endpoint is:

https://volare.cloud4wi.com/controlpanel/1.0/bridge/sessions/{SESSION_KEY}

Response when used in the Cloud4Wi Dashboard From Organization level

{
    "status": "success",
    "data": { 
        "lang": "eng",
        "auth": {
            "level": "tenant",
            "tenantId": "1001"
        }
    }
}

From Location level

{
    "status": "success",
    "data": {
        "lang": "eng",
        "auth": {
            "level": "wifiarea",
            "tenantId": "1001",
            "wifiareaId": "3246b0001"
        }
    }
}

Response when used in the Access Journey

User is Not logged in

{
    "status": "success",
    "data": { 
        "customer": {
            "is_logged": false,
            "lang": "eng"
        }, 
        "hotspot": {
            "city": "Livorno, Italy",
            "id": "9067",
            "identifier": "685112345D_illiade",
            "latitude": "45.960782503827",
            "longitude": "12.091283106750",
            "mac_address": "685112345D",
            "name": "Odissea",
            "state": "Livorno",
            "tag": "hotspot",
            "zip": "Livorno",
        },
        "tenant": {
            "name": "Taylor's Tenant",
            "read_only": false,
            "tenant_id": "1001"
        },
        "wifiarea": {
            "name": "Livorno Venue",
            "wifiarea_id": "18cde0005"
        }
    }
}

User Authenticated and logged in

{
    "status": "success",
    "data": { 
        "customer":{
            "is_logged":true,
            "lang":"eng",
            "id":"rlC.6yTePhzYg",
            "first_name":"John",
            "last_name":"Doe",
            "username":"706B5C1D",
            "gender":"",
            "birth_date":"0000-00-00 00:00:00",
            "phone":"",
            "phone_prefix":"",
            "email":"john.doe@cloud4wi.com",
            "mac_address":[]
        },
        "hotspot": {
            "city": "Livorno, Italy",
            "id": "9067",
            "identifier": "685112345D_illiade",
            "latitude": "45.960782503827",
            "longitude": "12.091283106750",
            "mac_address": "685112345D",
            "name": "Odissea",
            "state": "Livorno",
            "tag": "hotspot",
            "zip": "Livorno",
        },
        "tenant": {
            "name": "Taylor's Tenant",
            "read_only": false,
            "tenant_id": "1001"
        },
        "wifiarea": {
            "name": "Livorno Venue",
            "wifiarea_id": "18cde0005"
        }
    }
}

Example

Below an example in PHP that uses the session key to retrieve the context attributes.

< ?php

define('C4W_ENV_SPLASHPORTAL_URL', "https://splashportal.cloud4wi.com");
define('C4W_ENV_CONTROLPANEL_URL', "https://volare.cloud4wi.com");
define('C4W_ENV_MYAPPS_GET_SK_URL', "/controlpanel/1.0/bridge/sessions/");

function callApi() {

    if (isset($_GET['sk']))
    {
      $sk = $_GET['sk'];
    }

    // Check to see if any of the places where SK is set exists
    if(isset($sk) && !empty($sk)) {

        // Concatenate URL
        $url = constant('C4W_ENV_CONTROLPANEL_URL') . constant('C4W_ENV_MYAPPS_GET_SK_URL') . $sk; // https://volare.cloud4wi.com/controlpanel/1.0/bridge/sessions

        // Barebones call to the API using PHP curl
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $url
        ));
        $result = curl_exec($curl);
        $session = json_decode($result, true);

        // Create customer variable
        $c4w = array();
        if(isset($session['data']) && !empty($session['data'])) {
            $c4w = $session['data'];
        }

        // Return false if status of API call is not success
        if($session['status'] == 'success') {
            return $c4w;
        }
    }
    return false;
}


// GET DATA FROM SESSION
$data = callApi();

// Retrieving a specifc attribute
$phone = $data['customer']['phone'];

?>