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 Java code snippet below shows how you can get number of queued calls of your Africas Talking phone number using our API.

The code uses our Java gateway class: AfricasTalkingGateway.java [ Download]

To help decode JSON responses, you will need to add one of the available JAVA libraries as a dependency. For this tutorial we chose to use json-20090211.jar which you can download from this repository.

Note On SSL Certificate Validation Issues

Some of our users have experienced SSL Certificate validation issues when connecting to our website due to our use of https. The error you see may look something like this:

Unable to find valid certification path to requested target

Please do not panic! Our certificate is perfectly valid (as evidenced by these verification tests), and the error you are seeing is quite common amongst Java clients connecting to secure websites. Here is how to fix the issue:

  • Download and compile InstallCert.java (you can find the code here).
  • On the CMD prompt(Windows) or Terminal(*nix), run: java InstallCert api.africastalking.com
    This will download a copy of our Certificate and create a file named jssecacerts in the current directory.
  • You can now add our Certificate to your trusted store by copying the created jssecacerts file to the Java security directory under $JAVA_HOME/jre/lib/security
// Make sure the downloaded jar file is in the classpath
import org.json.*;

public class TestGetNumQueuedCalls
{
	public static void main(String[] args_)
	{
		// Specify your login credentials
		String username = "MyAfricasTalking_Username";
		String apiKey   = "MyAfricasTalking_APIKey";

		// Specify your Africa's Talking phone number in international format
		// Comma separate them for more than one number
		String phoneNumber = "+254711082XXX";

		// Create a new instance of our awesome gateway class
		AfricasTalkingGateway gateway  = new AfricasTalkingGateway(username, apiKey);

		/*************************************************************************************
			NOTE: If connecting to the sandbox:

			1. Use "sandbox" as the username
			2. Use the apiKey generated from your sandbox application
				https://account.africastalking.com/apps/sandbox/settings/key
			3. Add the "sandbox" flag to the constructor

			AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apiKey, "sandbox");
		**************************************************************************************/

		// Wrap the call in a try-catch block
		// Any gateway errors will be captured by our custom Exception class below
		try {
			JSONArray queuedCalls = gateway.getNumQueuedCalls(phoneNumber); 
			// For a specific queue, specify the queue name eg:
			// String queueName = "myQueueName"
			// JSONArray queuedCalls = gateway.getNumQueuedCalls(phoneNumber, queueName);
			int length = queuedCalls.length;
			for(int i = 0; i < length; i++) {
				JSONObject result = queuedCalls.getJSONObject(i);
				System.out.println("Phone number: " + result.getString("phoneNumber"));
				System.out.println("Queue name: " + result.getString("queueName"));
				System.out.println("Number of queued calls: " + result.getString("numCalls"));
			}
		} catch (Exception e) {
			System.out.println("Encountered an error" + e.getMessage());
		}
	}
}
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