Click Airtime

Migration Guide: V1 to V2

Step-by-step guide to migrate your integration from the Click Airtime Version 1 API to the Version 2 API.

The Version 2 API offers significant improvements including API key authentication, standardized responses, product catalog lookup, and comprehensive error handling. We strongly recommend migrating all existing V1 integrations.

What Changes in V2

Side-by-Side Comparison

FeatureV1 APIV2 API
AuthenticationHeader-based (email + token)API key (Bearer ce_live_xxx)
Base Path/adp/*/v2/*
Send AirtimePOST /adpPOST /v2/topups
Check BalancesGET /adp/balancesGET /v2/balance
Transaction HistoryGET /adp/transactionsGET /v2/topups
Product CatalogNot availableGET /v2/catalog/lookup
Response Formatcode: "1"/"0"success: true/false with structured errors
IdempotencyextRefId fieldIdempotency-Key header (same key within 24h returns the original result)
Rate Limits60 req/min (topup)60 req/min and 100 req/sec per API key by default (can be raised on request)
Phone FormatWithout + prefixE.164 with + prefix

Endpoint Mapping

V1 EndpointV2 EndpointNotes
POST /adpPOST /v2/topupsSimplified request body
GET /adp/balancesGET /v2/balanceReturns wallet-level balances
GET /adp/balances/:idGET /v2/balance/:wallet_idSingle wallet balance
GET /adp/transactionsGET /v2/topupsAdds pagination, filtering, sorting
N/AGET /v2/catalog/lookupNew: product catalog lookup
N/AGET /v2/topups/:idNew: re-check a single top-up

Migration Steps

Update Authentication

Replace header-based auth with API key authentication. Generate an API key from the Enterprise Portal under Settings > API Keys.

// V1: Header-based authentication
const response = await fetch('https://api.clickairtime.com/adp/balances', {
  headers: {
    'X-Click-Airtime-Email': 'your@email.com',
    'X-Click-Airtime-Token': 'your-api-token',
  },
});
// V2: API key authentication
const response = await fetch('https://api.clickairtime.com/v2/balance', {
  headers: {
    'Authorization': 'Bearer ce_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  },
});

API keys do not expire unless you set an expiry date when creating the key in the Enterprise Portal (after which requests return 401 EXPIRED_API_KEY). Any key can be revoked at any time from the Enterprise Portal. See Authentication for details.

Update Top-up Calls

The V2 API uses a request body with phone_number, network_id, and either amount (a custom amount in the destination's local currency, within the range from the catalog) or product_id (the integer id of a fixed bundle from the catalog). Look up the network_id and allowed amounts with GET /v2/catalog/lookup first.

// V1: Single call to send airtime
const result = await fetch('https://api.clickairtime.com/adp', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-Click-Airtime-Email': 'your@email.com',
    'X-Click-Airtime-Token': 'your-api-token',
  },
  body: JSON.stringify({
    msisdn: '233541112259',
    amount: 5,
    extRefId: 'txn_001',
  }),
}).then(r => r.json());

if (result.code === '1') {
  console.log('Success');
}
// V2: Create topup with API key auth
const result = await fetch('https://api.clickairtime.com/v2/topups', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer ce_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Content-Type': 'application/json',
    'Idempotency-Key': 'txn_001',
  },
  body: JSON.stringify({
    phone_number: '+233541112259',
    network_id: 11, // MTN Ghana, from GET /v2/catalog/lookup
    amount: { value: 5, currency: 'GHS' },
    reference: 'txn_001',
  }),
  signal: AbortSignal.timeout(30000),
}).then(r => r.json());

if (result.success) {
  // Synchronous: status is final ("completed")
  console.log('Delivered:', result.data.id, result.data.provider_reference);
  console.log('Charged:', result.data.cost.value, result.data.cost.currency);
}

Update Balance Checks

// V1: Get all balances
const balances = await fetch('https://api.clickairtime.com/adp/balances', {
  headers: {
    'X-Click-Airtime-Email': 'your@email.com',
    'X-Click-Airtime-Token': 'your-api-token',
  },
}).then(r => r.json());

// V1: Each network has a separate balance
balances.data.forEach(b => {
  console.log(`${b.serviceName}: ${b.balance} ${b.currency}`);
});
// V2: Get wallet balances
const balance = await fetch('https://api.clickairtime.com/v2/balance', {
  headers: {
    'Authorization': 'Bearer ce_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  },
}).then(r => r.json());

// V2: Total available balance
const total = balance.data.available_balance;
console.log(`Available: ${total.amount} ${total.currency}`);

// V2: Each wallet
balance.data.wallets.forEach(w => {
  console.log(`${w.id} (${w.type}): ${w.balance} ${w.currency}`);
});

Update Transaction Lookups

// V1: Search by phone number
const txns = await fetch(
  'https://api.clickairtime.com/adp/transactions?msisdn=233541112259',
  {
    headers: {
      'X-Click-Airtime-Email': 'your@email.com',
      'X-Click-Airtime-Token': 'your-api-token',
    },
  }
).then(r => r.json());
// V2: Full pagination and filtering
const txns = await fetch(
  'https://api.clickairtime.com/v2/topups?phone_number=%2B233541112259&page=1&per_page=20',
  {
    headers: {
      'Authorization': 'Bearer ce_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    },
  }
).then(r => r.json());

const { page, total_pages, total } = txns.meta.pagination;
console.log(`Total: ${total}, Page: ${page} of ${total_pages}`);

Update Error Handling

// V1: Check string code field
const result = await sendTopup();

if (result.code === '0') {
  // Parse the message string to understand the error
  console.error('Failed:', result.message);
}
// V2: Structured error codes
const result = await sendTopup();

if (!result.success) {
  switch (result.error.code) {
    case 'INSUFFICIENT_BALANCE':
      // Handle low balance
      break;
    case 'INVALID_PHONE_NUMBER':
      // Handle bad phone number
      break;
    case 'NETWORK_NOT_FOUND':
      // Handle unsupported destination
      break;
    default:
      console.error(`Error ${result.error.code}: ${result.error.message}`);
  }
}

Update Phone Number Formatting

The V2 API requires E.164 format (with the + prefix), while V1 used numbers without the prefix.

// V1 format: no plus prefix
const v1Phone = '233541112259';

// V2 format: E.164 with plus prefix
const v2Phone = '+233541112259';

// Simple conversion
function convertToV2Format(v1Phone) {
  return v1Phone.startsWith('+') ? v1Phone : `+${v1Phone}`;
}

Checklist

Use this checklist to track your migration progress:

  • Generate an API key from the Enterprise Portal
  • Replace header-based auth with Authorization: Bearer API key
  • Update top-up calls to use POST /v2/topups with network_id and either amount or an integer product_id from the catalog
  • Update balance checks to use GET /v2/balance
  • Update transaction lookups to use GET /v2/topups
  • Add + prefix to all phone numbers (E.164 format)
  • Replace code === "1" checks with success === true
  • Implement structured error handling using error.code
  • Add Idempotency-Key header for transaction creation
  • Set a client timeout of at least 30 seconds for POST /v2/topups, and retry timeouts with the same Idempotency-Key
  • Read cost (in your wallet's currency) and provider_reference from the top-up response for reconciliation
  • Switch production traffic to V2 endpoints

Need help migrating? Contact our developer support team at developers@clickairtime.com for personalized migration assistance.