Get your current account balance

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

Write the code

Add the following to account-balance.sh:

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

View full source

Run your code

Save this file to your machine and run it:

bash account-balance.sh

Prerequisites

Install dependencies

npm install nexmo
Initialize your dependencies

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

Copy to Clipboard
const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
})

View full source

Write the code

Add the following to account-balance.js:

Copy to Clipboard
nexmo.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

Install dependencies

composer require nexmo/client
Initialize your dependencies

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

Copy to Clipboard
$basic  = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\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->data['balance'], 2) . " EUR\n";

View full source

Run your code

Save this file to your machine and run it:

php account-balance.php

Prerequisites

Install dependencies

pip install nexmo
Initialize your dependencies

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

Copy to Clipboard
client = nexmo.Client(key=NEXMO_API_KEY, secret=NEXMO_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

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