Skip to main content

Obtaining cloud analytics data from CDS

· 3 min read
Sergey Dartchuk
Sergey Dartchuk
Software Engineer

This guide will help you get cloud analytics data from CDS using the API. We will use a common API approach as an example in this guide. The API calls will be triggered to fetch the necessary data whenever needed. Additionally, we will cover how to authenticate your requests and process the returned data effectively for your application's requirements.

Prerequisites

  • Node.js installed on your server.

Step-by-Step Guide

Step 1: Setting Up the Server

  1. Install Node.js and npm if not already installed. Follow the installation instructions from the official Node.js website: Node.js.

  2. Create a new project directory and navigate to it in your terminal:

    mkdir wildix-cds-ca
    cd wildix-cds-ca
  3. Initialize a new Node.js project:

    npm init -y
  4. Change type to module: add type to package.json

    "type": "module"
  5. Install necessary dependencies:

    npm i @wildix/cds-ca-client @wildix/auth-utils

Step 2.1: Creating a Script for CallHistory

Create a file named callHistory.js in your project directory and add the following code:

import { CdsCAClient, GetCallsCommand } from '@wildix/cds-ca-client';
import { OpenIdUserProvider } from '@wildix/auth-utils';

const AUD = 'cds-ca';
const SCOPE = 'get';
const USER = 'admin';
const PASS = 'your-pass';
const PBX = 'https://{pbx}.wildixin.com';

// Specify params for your request
const DATE_FROM = '2024-07-01';
const DATE_TO = '2024-08-01';

// Specify params for authentication
const authParams = {
pbxUri: PBX,
user: USER,
pass: PASS,
aud: AUD,
scope: SCOPE
};
const client = new CdsCAClient({token: new OpenIdUserProvider(authParams)});

async function run () {
const params = {
dateFrom: DATE_FROM,
dateTo: DATE_TO,
offset: 0,
limit: 100
}

return await client.send(new GetCallsCommand(params))
}


run()
.then(items => console.log(items))
.catch(e => console.error(e));

Step 2.2: Creating a Script for get dump file

Create a file named getDump.js in your project directory and add the following code:

import { CdsCAClient, CreateDumpCommand } from '@wildix/cds-ca-client';
import { OpenIdUserProvider } from '@wildix/auth-utils';

// Specify params for authentication
const AUD = 'cds-ca';
const SCOPE = 'get';
const USER = 'admin';
const PASS = 'your-pass';
const PBX = 'https://{pbx}.wildixin.com';
const TYPE = 'calls';

// Specify params for your request
const DATE_FROM = '2024-07-01';
const DATE_TO = '2024-08-01';

// Specify params for authentication
const authParams = {
pbxUri: PBX,
user: USER,
pass: PASS,
aud: AUD,
scope: SCOPE
};
const client = new CdsCAClient({token: new OpenIdUserProvider(authParams)});

const sleep = async (sec) => await new Promise((resolve) => setTimeout(resolve, sec * 1000));

async function run () {
const params = {
type: TYPE,
dateFrom: DATE_FROM,
dateTo: DATE_TO,
}

const { id } = await client.send(new CreateDumpCommand(params))

while (true) {
const { presignedDownloadUrl, status } = await client.send(new GetDumpCommand({id}));
console.log(status)
if (presignedDownloadUrl) {
return presignedDownloadUrl;
}
await sleep(10);
}
}


run()
.then(items => console.log(items))
.catch(e => console.error(e));

Step 3: Running the scripts

Start your Node.js server by running:

node callHistory.js
node getDump.js

Conclusion

This guide provided a step-by-step approach to get Cloud Analytics data from CDS. Customize the script as per your requirements to make the most out of this API.