Airtime Purchase Endpoint

Endpoint

URL: /api/airtimeapi

Methods: POST, GET

Description

This API endpoint allows users to purchase airtime credits for mobile phones.

Authentication

To access this endpoint, users must include their API key and secret key in the request headers.

Request Headers

  • api-key (string, required): The API key of the user.
  • secret-key (string, required): The secret key of the user.

Request Body (POST)

  • phone (string, required): The phone number to recharge.
  • firstLevel (string, required): The network of airtime to purchase.
  • amount (number, required): The amount of airtime to purchase.

Usage Example

See usage example in the code snippets below:

Example: Purchase Airtime

POST request to purchase airtime:


Content-Type: application/json
api-key: your-api-key
secret-key: your-secret-key

{
"phone": "08032566178",
"firstLevel": "MTN",
"amount": 100
}
      

Response:


- Status Code: 200

{
"message": "Transaction successful",
"airtimeHistory": {
"transactionId": "1234567890",
"email": "user@example.com",
"activity": "MTN airtime",
"status": "Success",
"recipient": "08032566178",
"amount": 100,
"amountUsed": 99,
"initialBalance": 500,
"finalBalance": 401
"Method": API,
}
}
- The `amountUsed` field represents the actual amount deducted from the user's balance based on user level.
      

Failed Response Format



{
"error": "Transaction failed",
"airtimeHistory": {
"transactionId": "1234567890",
"email": "user@example.com",
"activity": "MTN airtime",
"status": "Failed",
"recipient": "08032566178",
"amount": 100,
"initialBalance": 500,
"finalBalance": 500
"Method": API,
}
}
    

GET request

See usage example in the code snippets below:

Get the list of available firstLevel

GET request for available firstLevel:


Content-Type: application/json
api-key: your-api-key
secret-key: your-secret-key

      

Response:


- Status Code: 200

{
"MTN": {
  "available": true
},
"GLO": {
  "available": true
},
"AIRTEL": {
  "available": true
},
"9MOBILE": {
  "available": true
}
}            

Other Error Responses

  • 401 Unauthorized: Invalid API key or secret key.
  • 404 Not Found: User not found or data not available.
  • 500 Internal Server Error: Internal server error occurred.