List Queues
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
Using the FreeClimb SDK, invoke an asynchronous request for all Queues associated with the account. Additional criteria such as Alias
can be provided to limit the results. Successful invocation of the get
method returns the first page of Queues as a Queues
object. Iteration through the entire list of Queues uses the nextPageUri
.
Create your package.json file and save in the root directory of your project:
{
"name": "node-list-queues-how-to-guide",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"@freeclimb/sdk": "^3.8.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')
const accountId = process.env.ACCOUNT_ID
const apiKey = process.env.API_KEY
const configuration = freeclimbSDK.createConfiguration({ accountId, apiKey })
const freeclimb = new freeclimbSDK.DefaultApi(configuration)
getQueues().then(queues => {
console.log('got queues', queues)
}).catch(err => {
console.log(err)
})
async function getQueues() {
const queues = []
let response = await freeclimb.listActiveQueues()
queues.push(...response.queues)
while (response.nextPageUri) {
response = await freeclimb.getNextPage(response)
queues.push(...response.queues)
}
return queues
}
Java
After successfully creating the FreeClimbClient
, invoke getQueuesRequester
to send a synchronous request for all Queues associated with the account. Additional criteria such as alias
can be provided to limit results. Successful invocation of the get
method returns the QueueList
object, which allows for sequential iteration through the entire list of Queues.
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'] // changed line
}
}
}
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.queue.Queue;
import com.vailsys.freeclimb.api.queue.QueueList;
import com.vailsys.freeclimb.api.queue.QueuesSearchFilters;
import java.util.ArrayList;
public ArrayList listQueues() {
QueuesSearchFilters filters = new QueuesSearchFilters();
filters.setAlias("Tutorial Queue");
try {
// Create FreeClimbClient object
// accountId & apiKey can be found under API credentials on the FreeClimb Dashboard
FreeClimbClient client = new FreeClimbClient(accountId, apiKey);
//Invoke get method to retrieve the first page of queues with a matching alias
QueueList queueList = client.queues.get(filters);
//Check if the list is empty by checking its total size
if(queueList.getTotalSize() > 0){
//Retrieve all pages of results
while (queueList.getLocalSize() < queueList.getTotalSize()){
queueList.loadNextPage();
}
//Retrieve the inner ArrayList of queues to process
ArrayList<Queue> queues = queueList.export();
for (Queue queue:queues) {
//Process queue element in some way
}
return queues;
}
}
catch(FreeClimbException pe) {
System.out.println(pe.getMessage());
}
return null;
}
C#
After successfully creating the FreeClimbClient
, invoke getQueuesRequester
to send a synchronous request for all Queues associated with the account. Additional criteria such as alias
can be provided to limit results. Successful invocation of the get
method returns the QueueList
object, which allows for sequential iteration through the entire list of Queues.
Example code:
QueuesSearchFilters filters = null;
if (String.IsNullOrEmpty(Alias) == false)
{
filters = new QueuesSearchFilters();
filters.setAlias(Alias);
}
// Create FreeClimbClient object
FreeClimbClient client = new FreeClimbClient(getFreeClimbAccountId(),
getFreeClimbApiKey());
// Invoke get method to retrieve initial list of queue information
QueueList queueList = client.getQueuesRequester.get(filters);
Console.Write($"Number of queues: {queueList.getTotalSize} \n" );
// Check if list is empty by checking total size of the list
if (queueList.getTotalSize > 0)
{
// retrieve all queue information from server
while (queueList.getLocalSize < queueList.getTotalSize)
{
queueList.loadNextPage();
}
// Convert current pages queue information to a linked list
LinkedList<IFreeClimbCommon> commonList = queueList.export();
// Loop through linked list to process queue information
foreach (IFreeClimbCommon element in commonList)
{
// Cast each element to the Queue element for processing
Queue queue = element as Queue;
// Process queue element
}
}
Updated 2 months ago