Get user balance

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 VB.NET code snippet below shows how to get user balance from 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 = "myAfricasTalkingUsername"
			Dim apikey As String   = "myAPIKey"
			
			' Create a new instance of our awesome gateway class
			Dim gateway As New AfricasTalkingGateway(username, apikey)
			
			' Wrap the function call in a Try block
			' Any Exception will be captured by our custom AfricasTalkingException class
			
			Try
				Object userData = gateway.getUserData()
				Dim balance As String = userData("balance")
				System.Console.WriteLine("Balance: " + balance)
				' The result will have the format=> KES XXX
				
			catch ex As AfricasTalkingGatewayException
				System.Console.WriteLine(ex.Message())
		
		End Try 
	End Sub
End Class

To access your data (eg. balance from our API), you will need to make a HTTP GET request to the following url:
GET URL: https://api.africastalking.com/version1/user
The server shall expect:
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 URL This is your Africa'sTalking username Yes
Upon successful processing, the server shall respond in the following format:
XML
<?xml version="1.0"?>
  <AfricastalkingResponse>
    <UserData>
      <balance> XXX</balance>
    </UserData>
</AfricastalkingResponse>
JSON

{"UserData" :
  {
    "balance" : " XXX"
  }
}
Example using CURL client
curl -H "Accept: application/xml" -H "Apikey:myAPIKey" "https://api.africastalking.com/version1/user?username=myUsername" --insecure