Get Balance
curl --request GET \
--url https://api.example.com/api/agent_balance \
--header 'API-KEY: <api-key>'import requests
url = "https://api.example.com/api/agent_balance"
headers = {"API-KEY": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'API-KEY': '<api-key>'}};
fetch('https://api.example.com/api/agent_balance', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/agent_balance",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/agent_balance"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("API-KEY", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/api/agent_balance")
.header("API-KEY", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/agent_balance")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["API-KEY"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"balance": {
"balance": 0,
"overdraft": 2000
}
}
{
"error": {
"message": "Invalid or missing API key",
"code": "authentication_error"
},
"success": "false"
}
Endpoints
Get Balance
Returns merchant balance in cents
GET
/
api
/
agent_balance
Get Balance
curl --request GET \
--url https://api.example.com/api/agent_balance \
--header 'API-KEY: <api-key>'import requests
url = "https://api.example.com/api/agent_balance"
headers = {"API-KEY": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'API-KEY': '<api-key>'}};
fetch('https://api.example.com/api/agent_balance', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/agent_balance",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/agent_balance"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("API-KEY", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/api/agent_balance")
.header("API-KEY", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/agent_balance")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["API-KEY"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"balance": {
"balance": 0,
"overdraft": 2000
}
}
{
"error": {
"message": "Invalid or missing API key",
"code": "authentication_error"
},
"success": "false"
}
Overview
Returns the current balance and overdraft limit for your merchant account. All amounts are returned in cents.Endpoint
GET /api/agent_balance
Authentication
string
required
Your CashQ API Key for authentication
Request Example
curl -X GET 'https://api.cashqbot.com/api/agent_balance' \
-H 'API-KEY: your_api_key_here'
const response = await fetch('https://api.cashqbot.com/api/agent_balance', {
method: 'GET',
headers: {
'API-KEY': 'your_api_key_here'
}
});
const data = await response.json();
console.log(data);
import requests
response = requests.get(
'https://api.cashqbot.com/api/agent_balance',
headers={'API-KEY': 'your_api_key_here'}
)
data = response.json()
print(data)
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.cashqbot.com/api/agent_balance');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'API-KEY: your_api_key_here'
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data);
?>
Response
object
Response Example
{
"balance": {
"balance": 0,
"overdraft": 2000
}
}
{
"error": {
"message": "Invalid or missing API key",
"code": "authentication_error"
},
"success": "false"
}
Understanding the Response
Balance Calculation
Your available funds =balance + overdraft
Example:
- Balance: 1000 cents ($10.00)
- Overdraft: 2000 cents ($20.00)
- Available funds: 3000 cents ($30.00)
When to Check Balance
Before Transfers
Check balance before initiating large transfers to ensure sufficient funds
Regular Monitoring
Monitor balance regularly to avoid insufficient funds errors
After Deposits
Verify balance after adding funds to your account
Error Recovery
Check balance when receiving insufficient funds errors
Error Responses
| Error Code | Description | Solution |
|---|---|---|
authentication_error | Invalid or missing API key | Verify your API key is correct and included in the header |
internal_server_error | Server error occurred | Retry the request after a brief delay |
Best Practices
Cache balance appropriately
Cache balance appropriately
Don’t check balance before every single transaction. Cache the balance for a reasonable time (e.g., 5 minutes) to reduce API calls.
Handle overdraft correctly
Handle overdraft correctly
Remember to include overdraft when calculating available funds. Don’t just check the balance field.
Convert to dollars for display
Convert to dollars for display
Balance is returned in cents. Always divide by 100 when displaying to users.
Monitor balance regularly
Monitor balance regularly
Set up automated monitoring to alert you when balance falls below a threshold.
Related Endpoints
Money Transfer
Initiate a money transfer after confirming sufficient balance
Check Transfer
Validate transfer details before execution
