Number of queued calls

You need your AfricasTalking username and APIKey for any request to our API. If you don't have an APIKey, please click here to get one.

The Node.js code snippet below shows how you can get number of queued calls of your Africas Talking phone number using our API.

// Import the required libraries
var querystring = require('querystring');
var https       = require('https');

// Your login credentials
var username  = 'MyUsername';
var apikey    = 'MyApiKey';

// Specify your AfricasTalking phone number in the international format
// Comma separate the  numbers if they are more than one
var phoneNumber = "+254711082XXX";

//set queueName = null if no queue name is set
var queueName = "myQueueName";

function getQueuedCalls() {
	//Build post string from object
	var post_data = {
		                 'username'     : username,
		                 'phoneNumbers'  : phoneNumber
		               }
	
	if(queueName)
	 post_data.queueName = queueName;
	
	post_data = querystring.stringify(post_data);
	
	//create request parameters
	var request_parameters = {
       host               : 'voice.africastalking.com',
       port               : 443,
       path               : '/queueStatus',
       method             : 'POST',
       
       rejectUnauthorized : false,
       requestCert        : true,
       agent              : false,

       headers : {

         'Content-Type'    : 'application/x-www-form-urlencoded',
         'Content-Length'  : post_data.length,
         'apikey'          : apikey,
         'Accept'          : 'application/json'
      }
	 }
	 
	 var request = https.request(request_parameters, function (response) {
			response.setEncoding('utf8');
			response.on('data', function (data_chunk) {
			 try {
			 	var jsObject = JSON.parse(data_chunk);
			 	if(jsObject.errorMessage != "None")
			 	 throw jsObject.errorMessage;
			 	 
			 	 var entries = jsObject.entries;
			 	 var logStr = "";
			 	 
			 	 for(result in entries) {
			 	 	logStr  += '\nPhone numbers : ' + entries.phoneNumber;
			 	 	logStr  += ';Queue name : ' + entries.queueName;
			 	 	logStr  += ';Number of queued calls : ' + entries.numCalls;
			 	 }
			 	 console.log(logStr);
   		}
   		catch (error) {
   			console.log('Error: ' + error);
   			}
   		});
   	});
	
	request.write(post_data);
	request.end();
	
}
//Call get user function;
getQueuedCalls();

Our REST resource for getting the number of queued calls is located at: https://voice.africastalking.com/queueStatus. In order to get the number of queued calls, you will need to pass in the following parameters within a POST request:
Variable Name Location Description
apikey Header Your API Key, which you can generate from your dashboard
username Body Your Africa's Talking account username
phoneNumbers Body Your AfricasTalking phone number mapped to your account

You can check the HTTP Response Code to determine whether the request was successful. Any response code other than 201 (Created) indicates that the call was not initiated

Example using CURL client
curl -H "Accept: application/xml" -H "Apikey: fb752d3417021812f0961y6c9464832dd1adb1e555c73f1e7c32bcc006488674" -d "username=myUsername&phoneNumbers=+254711082XXX" https://voice.africastalking.com/queueStatus