Mobile Recharge API in Bangladesh: A Complete Integration Guide

By Supayo 2 min read
Mobile Recharge API Integration Guide

If you are running a shop app, an e-commerce site with a top-up feature, or a bulk recharge tool, doing it by hand stops working quickly. A recharge API turns each sale into one HTTP request.

What you need before writing code

  • A reseller account with API access enabled
  • An API key
  • Your server's public IP whitelisted
  • Balance in the account

The IP whitelist catches most people. A key that works from your laptop will be refused from your production server until that address is added.

The three endpoints

PurposeEndpoint
Send a rechargePOST /sendapi/request
Check statusPOST /sendapi/status
Read balancePOST /sendapi/balance

Operator codes

OperatorCodePrefixes
GrameenphoneGP017, 013
RobiRB018
BanglalinkBL019, 014
AirtelAT016
TeletalkTT015
SkittoSK017

Skitto numbers use GP prefixes but need their own code — sending them as GP is the single most common integration bug.

Sending a recharge

<?php
$post = [
  'user'     => '01XXXXXXXXX',
  'key'      => 'your_api_key',
  'number'   => '017XXXXXXXX',
  'amount'   => '50',
  'service'  => '64',
  'type'     => '1',          // 1 prepaid, 2 postpaid
  'operator' => 'GP',
  'id'       => 'BD' . date('dmyHis') . mt_rand(100, 999),
];

$ch = curl_init('https://yourdomain.com/sendapi/request');
curl_setopt_array($ch, [
  CURLOPT_HTTPHEADER     => ['band-key: yourbandkey'],
  CURLOPT_POST           => true,
  CURLOPT_POSTFIELDS     => $post,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT        => 30,
]);
$res = json_decode(curl_exec($ch), true);

The id field is yours

You generate it, you store it, and it is how you find the transaction later. Make it unique per request and save it against your order before you send. If the request times out you still know what to look up.

A success response does not mean delivered

{"success": true, "status": 1, "message": "Request Submit Successfully"}

This means accepted, not completed. The operator has not been contacted yet. Recharges settle anywhere from two seconds to two minutes later. Show your customer "processing", never "done".

Finding out the result

Two options.

Polling

Call /sendapi/status every few seconds until it stops being pending. Simple, wasteful, and slow for the customer.

Webhooks

Register a URL and receive one signed POST the moment the outcome is known. One request instead of twenty-four, and the customer sees the result immediately. Use this if it is available.

Node.js

const body = new URLSearchParams({
  user: '01XXXXXXXXX', key: 'your_api_key',
  number: '017XXXXXXXX', amount: '50',
  service: '64', type: '1', operator: 'GP',
  id: 'BD' + Date.now()
});

const res = await fetch('https://yourdomain.com/sendapi/request', {
  method: 'POST',
  headers: { 'band-key': 'yourbandkey' },
  body
});
console.log(await res.json());

Python

import requests, time

r = requests.post('https://yourdomain.com/sendapi/request',
    headers={'band-key': 'yourbandkey'},
    data={'user':'01XXXXXXXXX','key':'your_api_key',
          'number':'017XXXXXXXX','amount':'50','service':'64',
          'type':'1','operator':'GP',
          'id':'BD'+str(int(time.time()*1000))},
    timeout=30)
print(r.json())

Things that will bite you

  • Reusing an id. Generate a fresh one per attempt, or your retry looks like the original.
  • Retrying a timeout blindly. A timeout means unknown, not failed. Check status first or you will recharge twice.
  • Not checking balance. An empty account fails every request. Alert yourself before it hits zero.
  • Hardcoding the operator. Derive it from the prefix, and ask the customer when it is ambiguous.
Share WhatsApp
WhatsApp