> For the complete documentation index, see [llms.txt](https://create.cloud4wi.ai/dev-hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://create.cloud4wi.ai/dev-hub/myapps/myapps-apis-and-sdk/context-apis.md).

# 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<br>

### **Using Context APIs**<br>

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"
        }
    }
}
```

```
{
    "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<br>

```
{
    "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'];

?>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://create.cloud4wi.ai/dev-hub/myapps/myapps-apis-and-sdk/context-apis.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
