Send Airtime

You need your AfricasTalking username and APIKey for any request to our API. If you don't have an APIKey, you can generate one from your applications settings page.

The CSharp code snippet below shows how to send airtime using our API.

The code uses our CSharp gateway class: AfricasTalkingGateway.cs [ Download]

We use the Javascript serializer to encode and decode data so be sure to add System.Web.Extensions and System.Microsoft.CSharp as your referenced libraries in you project.

using System;

class MainClass
	static public void Main (){
	// Specify your login credentials
		string username = "MyApp_Username";
		string apiKey   = "MyApp_APIKey";
		// Specify an array list to hold numbers to receive airtime
		ArrayList AirtimeRecipientsList = new ArrayList();
		// Declare hashtable to hold the first number
		// Please ensure you include the country code for phone numbers (+254 for Kenya in this case)
		// Please ensure you include the country code for phone numbers (KES for Kenya in this case)
		// Specify the country currency and the amount as shown below
		Hashtable rec1      = new Hashtable();
		rec1["phoneNumber"] = "+254711XXXYYY";
		rec1["amount"]      = "KES XXX";
		// Add recipient to list
		// Declare hashtable to hold the another number
		Hashtable rec2     = new Hashtable();
		rec2["phoneNumber"] = "+254733YYYZZZ";
		rec2["amount"]      = "KES XXX";
		// Add recipient to list
  // Create a new instance of our awesome gateway class
		AfricasTalkingGateway gateway = new AfricasTalkingGateway (username, apiKey);
	 try {
				// That's it. Hit send and we will handle the rest
				dynamic response = gateway.sendAirtime(AirtimeRecipientsList);
				foreach (dynamic result in response) {
					Console.Write (result["status"] + ",");
					Console.Write (result["phoneNumber"] + ",");
					Console.Write (result["amount"] + ",");
					Console.Write (result["discount"] + ",");
					Console.WriteLine (result["errorMessage"]);
			catch(AfricasTalkingGatewayException ex) {
				Console.WriteLine (ex.Message);

To send airtime you will need to make a HTTP POST request to the following url:


We however have a limit of the amount you can send as shown below:

Minimum amount Maximum amount
KES 10 KES 10,000
The server expects:
Parameter Location Description Required
API key Header API key generated from your account settings Yes
Accept Header This is the format you would like your data formatted. It may be application/xml or application/json. The default is application/xml. The gateway classes provided uses appliaction/json. No
username Body This is your Africa'sTalking username Yes
recipients Body Contains the a list of airtime recipients in JSON format. It should look like:
[{"phoneNumber":"+254711XXXYYY","amount":"KES X"},{"phoneNumber":"+254733YYYZZZ","amount":"KES Y"}]
Upon successful processing, the server shall respond in the following format:
<?xml version="1.0"?>
    <totalAmount>KES XXX</totalAmount>
    <totalDiscount>KES YYY</totalDiscount>
        <amount>KES 1000.0000</amount>
        <amount>KES 2000.0000</amount>

 "numSent": n,
 "totalAmount": "KES XXX",
 "totalDiscount" : "KES YYY",
 "responses" : [
        "amount":"KES 1000",
        "amount":"KES 2000",