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 VB.NET code snippet below shows how to airtime using our API.

The code uses VB gateway class: AfricasTalkingGateway.vb [ Download]

The code encodes and decodes data using Javascript serializer so you will need to add System.Web.Extensions to your referenced libraries

Imports System.IO
Imports System.Collections
Imports System.Collections.Generic

Public Class Application
	Public Shared Sub Main()
			' Specify your login credentials
			Dim username As String = "MyAppUsername"
			Dim apikey As String   = "myAPIKey"
			' Specify an list to hold the airtime recipient numbers and the amount to be sent
			Dim airtimeRecipientsList As New List(Of Hashtable)()
			' Declare hashtable to hold the first recipient and amount sent to them
			' Please ensure you include the country code for phone numbers (+254 for Kenya in this case)
			' Specify the country currency and the amount as shown below (KES for Kenya in this case)
			Dim recipient1 As New Hashtable()
			recipient1("phoneNumber") = "+254711XXXYYY"
			recipient1("amount")      = "KES XX"
			' Add the recipient to airtimeRecipientsList
			' Declare hashtable to hold the second recipient
			Dim recipient2 As New Hashtable()
			recipient2("phoneNumber") = "+254733YYYZZZ"
			recipient2("amount")      = "KES YY"
			' Add the recipient to airtimeRecipientsList
			' Create a new instance of our awesome gateway class
			Dim gateway As New AfricasTalkingGateway(username, apikey)
			 ' Hit send and we will handle the rest
				Dim response as object()= gateway.sendAirtime(airtimeRecipientsList)
				Dim result as object
				for each result in response
					System.Console.WriteLine("Status: " + result("status"))
					System.Console.WriteLine("RequestID: " + result("requestId"))
					System.Console.WriteLine("phoneNumber: " + result("phoneNumber"))
					System.Console.WriteLine("Discount: " + result("discount"))
					System.Console.WriteLine("amount: " + result("requestId"))
					' Incase the status result is Failed
					System.Console.WriteLine("ErrorMessage: " + result("errorMessage"))
		catch ex As AfricasTalkingGatewayException
		End Try 
	End Sub
End Class

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",