API Version: 6.5

Samples

Common sample code

Each of the samples will exist within a browser webpage.
That webpage will need to load the initial API, then authenticate and usually it will start the live data feed.
Rather than repeat the description of that process in each sample application, the following section provides the basic skeleton that will wrap most applications.
The examples all contain the URL of https://pabx.hostname/ which will need substituting for the actual URL/hostname of the IPCortex Communication System (CS) which the application is to run against. It is necessary to use HTTPS in order to avoid the browser complaining about cross-site scripting and insecure data in the page.

Loading all files directly

This method loads the API Javascript files directly as shown in the <head> tag. It is then necessary for the page (or an included application) to call:
  • setHost(): Let the application know where the API was loaded from.
  • Auth.login(): Present a login prompt for the user
  • PBX.startFeed(): Assuming live data is needed, start the data feed.
  • runApp(): For the purposes of these examples, the application will be started using this call.
Each of these steps has a simple error handler that displays a message.
<!doctype html>
<html>
<head>
    <title>IPC</title>
    <script src="https://pabx.hostname/api/api.js"></script>
</head>
<body>
<script>
    var TAG = 'IPC:';
    IPCortex.PBX.Auth.setHost('https://pabx.hostname');
    /* Display a login prompt */
    IPCortex.PBX.Auth.login().then(
        function() {
            console.log(TAG, 'Login successful');
            /* Get the API to start collecting data */
            IPCortex.PBX.startFeed().then(
                function() {
                    console.log(TAG, 'Live data feed started');
                    runApp();
                },
                function() {
                    console.log(TAG, 'Live data feed failed');
                }
            );
        },
        function() {
            console.log(TAG, 'Login failed');
        }
    );

    function runApp() {
        /* Implement application here */
    }
</script>
</body>
</html>

Loading Using a helper

This method uses one of the helper files to load the needed API Javascript files. These helpers can detect the IPCortex CS URL and automatically call setHost(). It is still necessary to complete the remaining steps which occur inside the onAPILoadReady() function:
  • Auth.login(): Present a login prompt for the user
  • PBX.startFeed(): Assuming live data is needed, start the data feed.
  • runApp(): For the purposes of these examples, the application will be started using this call.
Each of these steps has a simple error handler that displays a message.
<!doctype html>
<html>
<head>
    <title>IPC</title>
    <script src="http://pabx.hostname/api/wrapper.whtm"></script>
</head>
<body>
<script>
    var TAG = 'IPC:';
    /* Wait for API to confirm it is loaded - setHost() is called automatically for us */
    function onAPILoadReady() {
        /* Display a login prompt */
        IPCortex.PBX.Auth.login().then(
            function() {
                console.log(TAG, 'Login successful');
                /* Get the API to start collecting data */
                IPCortex.PBX.startFeed().then(
                    function() {
                        console.log(TAG, 'Live data feed started');
                        runApp();
                    },
                    function() {
                        console.log(TAG, 'Live data feed failed');
                    }
                );
            },
            function() {
                console.log(TAG, 'Login failed');
            }
        );
    }

    function runApp() {
        /* Implement application here */
    }
</script>
</body>
</html>

Sample applications

Below are some mini-applications to walk you through some the API's features:

Github

All of our samples can also be found in our GitHub repository, which is available for cloning:
git clone https://github.com/ipcortex/api-samples.git