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.
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'];
?>