Get your current account balance

You can check the balance of your Vonage account at any time by making an API request and receiving the balance of your account in the response.

Key Description
VONAGE_API_KEY Your Vonage API key (see it on your dashboard).
VONAGE_API_SECRET Your Vonage API secret (also available on your dashboard).

Write the code

Add the following to account-balance.sh:

Copy to Clipboard
curl "https://rest.nexmo.com/account/get-balance?api_key=$VONAGE_API_KEY&api_secret=$VONAGE_API_SECRET"

View full source

Run your code

Save this file to your machine and run it:

bash account-balance.sh

Prerequisites

npm install @vonage/server-sdk

Create a file named account-balance.js and add the following code:

Copy to Clipboard
const vonage = new Vonage({
  apiKey: VONAGE_API_KEY,
  apiSecret: VONAGE_API_SECRET
})

View full source

Write the code

Add the following to account-balance.js:

Copy to Clipboard
vonage.account.checkBalance((err, result) => {
    console.log(`${result.value.toFixed(2)} EUR`);
});

View full source

Run your code

Save this file to your machine and run it:

node account-balance.js

Prerequisites

Add the following to `build.gradle`:

compile 'com.vonage:client:5.5.0'

Create a class named GetBalance and add the following code to the main method:

Copy to Clipboard
VonageClient client = VonageClient.builder()
        .apiKey(VONAGE_API_KEY)
        .apiSecret(VONAGE_API_SECRET)
        .build();

View full source

Write the code

Add the following to the main method of the GetBalance class:

Copy to Clipboard
AccountClient accountClient = client.getAccountClient();

BalanceResponse response = accountClient.getBalance();
System.out.printf("Balance: %s EUR\n", response.getValue());
System.out.printf("Auto-reload Enabled: %s\n", response.isAutoReload());

View full source

Run your code

We can use the application plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:

Copy to Clipboard
  apply plugin: 'application'
  mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''

Run the following gradle command to execute your application, replacing com.vonage.quickstart.account with the package containing GetBalance:

gradle run -Pmain=com.vonage.quickstart.account.GetBalance

Prerequisites

Install-Package Vonage

Create a file named GetBalance.cs and add the following code:

Copy to Clipboard
using Vonage;
using Vonage.Request;
using Vonage.Accounts;

View full source

Add the following to GetBalance.cs:

Copy to Clipboard
var credentials = Credentials.FromApiKeyAndSecret(VONAGE_API_KEY, VONAGE_API_SECRET);
var client = new VonageClient(credentials);

View full source

Write the code

Add the following to GetBalance.cs:

Copy to Clipboard
var response = client.AccountClient.GetAccountBalance();

View full source

Prerequisites

composer require vonage/client

Create a file named account-balance.php and add the following code:

Copy to Clipboard
$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

View full source

Write the code

Add the following to account-balance.php:

Copy to Clipboard
$response = $client->account()->getBalance();
echo round($response->getBalance(), 2) . " EUR\n";

View full source

Run your code

Save this file to your machine and run it:

php account-balance.php

Prerequisites

pip install vonage

Create a file named get-balance.py and add the following code:

Copy to Clipboard
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)

View full source

Write the code

Add the following to get-balance.py:

Copy to Clipboard
result = client.get_balance()
print(f"{result['value']:0.2f} EUR")

View full source

Run your code

Save this file to your machine and run it:

python get-balance.py

Prerequisites

gem install vonage

Create a file named get-balance.rb and add the following code:

Copy to Clipboard
client = Vonage::Client.new(
  api_key: VONAGE_API_KEY,
  api_secret: VONAGE_API_SECRET
)

View full source

Write the code

Add the following to get-balance.rb:

Copy to Clipboard
puts "#{client.account.balance.value.round(2)} EUR"

View full source

Run your code

Save this file to your machine and run it:

ruby get-balance.rb

The example will output the current balance of your account in Euro.