List Calls

👍

You're ready for this how-to guide if you've got the following:

A FreeClimb account
A registered application
A configured FreeClimb Number
Your tools and language installed


Node.js

To initiate any interaction with FreeClimb a FreeClimb object must be created. An asynchronous request for all calls associated with the account can be initiated. Successful invocation of the GET method will return a call list which will return the URI of the next page of results.

Create your package.json file and save in the root directory of your project:

{
  "name": "node-list-calls-how-to-guide",
  "version": "1.0.0",
  "license": "MIT",
  "dependencies": {
    "@freeclimb/sdk": "^1.0.0",
    "dotenv": "^8.1.0"
  }
}

Install the package by running the following in the command line/terminal:

yarn install

Example code:

require('dotenv').config()
const freeclimbSDK = require('@freeclimb/sdk')
// your FreeClimb API credentials (available in the Dashboard) - be sure to set up environment variables to store these values
const accountId = process.env.ACCOUNT_ID
const apiKey = process.env.API_KEY
const freeclimb = freeclimbSDK(accountId, apiKey)
getCallsList().then(calls => {
  // Use the calls
}).catch(err => {
  // Catch Errors
})
 
async function getCallsList() {
  // Create array to store all calls
  const calls = []
  // Invoke GET method to retrieve initial list of call information
  const first = await freeclimb.api.calls.getList()
  calls.push(...first.calls)
  // Get Uri for next page
  let nextPageUri = first.nextPageUri
  // Retrieve entire call list
  while (nextPageUri) {
    const nextPage = await freeclimb.api.calls.getNextPage(nextPageUri)
    calls.push(...nextPage.calls)
    nextPageUri = nextPage.nextPageUri
  }
  return calls
}

Java

To initiate any interaction with FreeClimb a FreeClimbClient object must be created. Using the CallsRequester created upon successful creation of the FreeClimbClient a synchronous request for all calls associated with the account can be initiated. Successful invocation of the GET method will return the CallsList object which will allow for the sequential iteration through the entire list of calls.

Create your build.gradle file and save it to the root directory in your project:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This is a general purpose Gradle build.
 * Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds
 */

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
  //Add the dependency
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE"
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-spring-boot'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile "org.springframework.boot:spring-boot-starter-web"
    testCompile "junit:junit"
    compile 'com.github.FreeClimbAPI:FreeClimb-Java-SDK:3.0.0'
}

sourceSets {
    main {
        java {
            srcDirs = ['src']
        }
    }
}

Build the file by running the following in your terminal/command line:

gradle build

Example code:

import com.vailsys.freeclimb.api.FreeClimbClient;
import com.vailsys.freeclimb.api.FreeClimbException;
import com.vailsys.freeclimb.api.call.Call;
import com.vailsys.freeclimb.api.call.CallList;
 
import java.util.ArrayList;
public ArrayList listCalls() {
    FreeClimbClient client;
    CallList callsList;
 
    try {
        // Create FreeClimbClient object
        // accountId & apiKey can be found under API keys on the FreeClimb Dashboard
        client = new FreeClimbClient(accountId, apiKey);
        callsList = client.calls.get(); //Retrieve the paginated list of calls
 
        //Don't bother trying to grab more pages if there is only one or zero
        //pages of results
        if(callsList.getTotalSize() > callsList.getPageSize()) {
            //Load in all the calls returned.
            while(callsList.getLocalSize() < callsList.getTotalSize()) {
            callsList.loadNextPage(); //Load in the next page of calls.
            }
        }
 
        ArrayList<Call> allCalls = callsList.export(); //Extract the array from the CallList
 
        for(Call r : allCalls) {
            // do something with each call
        }
 
        return allCalls;
    }
    catch(FreeClimbException pe) {
        System.out.println(pe.getMessage());
    }
    return null;
}

C#

To initiate any interaction with FreeClimb a FreeClimbClient object must be created. Using the CallsRequestor created upon successful creation of the FreeClimbClient a synchronous request for all calls associated with the account can be initiated. Successful invocation of the GET method will return the CallList object which will allow for the sequential iteration through the entire list of calls.

Example code:

FreeClimbClient client = new FreeClimbClient (freeClimbAccountId, freeClimbApiKey);
CallList callList = client.getCallsRequester.get ();
if (callList.getTotalSize > 0) {
  while (callList.getLocalSize < callList.getTotalSize) {
    callList.loadNextPage ();
  }
  LinkedList<IFreeClimbCommon> commonList = callList.export ();
  foreach (IFreeClimbCommon element in commonList) {
    Call call = element as Call;
    Console.WriteLine (call.getCallId);
  }
}