Datamart
Datamart
Your mobile data solution
User Account
View profile

DataMart API Documentation

Mobile Data Bundle Purchase API for Ghana Networks

DataMart provides a simple and reliable API for purchasing mobile data bundles for customers in Ghana. This documentation will help you integrate with our service to programmatically purchase data bundles for any supported network.

Join our developer community for updates, support, and discussions:

Join Our WhatsApp Group

Authentication

To access the DataMart API, you'll need an API key. Include it in your request headers as:

X-API-Key: your_api_key_here

API Key Management

You can manage your API keys using the following endpoints:

Generate a new API key:

POST /api/developer/generate-api-key

Body:

{
  "name": "My API Key",
  "expiresIn": 365  // Optional: Days until expiry
}

List your API keys:

GET /api/developer/api-keys

Revoke an API key:

DELETE /api/developer/api-keys/:id

Data Purchase Endpoint

POST https://datamartbackened.onrender.com/api/developer/purchase

Endpoint to purchase mobile data for a phone number

Request Body:

{
  "phoneNumber": "0551234567",  // Recipient's phone number
  "network": "TELECEL",         // Network identifier (see options below)
  "capacity": "5",              // Data capacity in GB
  "gateway": "wallet"           // Payment method (default: wallet)
}

Supported Networks:

  • TELECEL - Vodafone Ghana
  • YELLO - MTN Ghana
  • AT_PREMIUM - AirtelTigo Ghana

Success Response (201):

{
  "status": "success",
  "data": {
    "purchaseId": "60f1e5b3e6b39812345678",
    "transactionReference": "TRX-a1b2c3d4-...",
    "network": "TELECEL",
    "capacity": "5",
    "mb": "5000",
    "price": 23.00,
    "remainingBalance": 177.00,
    "geonetechResponse": { ... }
  }
}

Error Response:

{
  "status": "error",
  "message": "Error message description",
  "details": { ... }  // Optional additional details
}

Note: Ensure your wallet has sufficient balance before making a purchase request. You can check your wallet balance from your dashboard.

Available Data Packages

To get available data packages for a specific network, use the GET /api/developer/data-packages endpoint:

GET /api/developer/data-packages?network=TELECEL

Response:

{
  "status": "success",
  "data": [
    {
      "capacity": "5",
      "mb": "5000",
      "price": "23.00",
      "network": "TELECEL"
    },
    {
      "capacity": "10",
      "mb": "10000",
      "price": "35.50", 
      "network": "TELECEL"
    },
    // More packages...
  ]
}

You can also get packages for all networks at once:

GET /api/developer/data-packages

Response (All Networks):

{
  "status": "success",
  "data": {
    "TELECEL": [
      // Vodafone packages
    ],
    "YELLO": [
      // MTN packages
    ],
    "AT_PREMIUM": [
      // AirtelTigo packages
    ]
  }
}

Additional Endpoints

Transaction History

Retrieve transaction history for your account:

GET /api/developer/transactions?page=1&limit=20

Response:

{
  "status": "success",
  "data": {
    "transactions": [
      {
        "_id": "60f1e5b3e6b39812345678",
        "userId": "60f1e5b3e6b39812345679",
        "type": "purchase",
        "amount": 23.00,
        "status": "completed",
        "reference": "TRX-a1b2c3d4-...",
        "gateway": "wallet",
        "createdAt": "2023-01-01T12:00:00.000Z",
        "updatedAt": "2023-01-01T12:00:00.000Z"
      },
      // More transactions...
    ],
    "pagination": {
      "currentPage": 1,
      "totalPages": 5,
      "totalItems": 92
    }
  }
}

Claim Referral Bonus

Claim any pending referral bonuses for your account:

POST /api/developer/claim-referral-bonus

Response:

{
  "status": "success",
  "data": {
    "bonusClaimed": 15.00,
    "processedBonuses": ["60f1e5b3e6b39812345680", "60f1e5b3e6b39812345681"],
    "newWalletBalance": 192.00
  }
}

API Simulator

Test the Data Purchase API with your own API key:

Note: This is a simulation tool for testing purposes only. No actual API calls are made, and no data bundles are purchased. Use this tool to understand how the API works before integrating it into your application.

Code Samples

Next.js Example:

// pages/api/purchase-data.js
import axios from 'axios';

export default async function handler(req, res) {
  if (req.method !== 'POST') {
    return res.status(405).json({ message: 'Method not allowed' });
  }

  const { phoneNumber, network, capacity } = req.body;
  
  // Validate required fields
  if (!phoneNumber || !network || !capacity) {
    return res.status(400).json({ 
      message: 'Missing required fields' 
    });
  }

  try {
    const response = await axios.post(
      'https://datamartbackened.onrender.com/api/developer/purchase',
      {
        phoneNumber,
        network,
        capacity,
        gateway: 'wallet'
      },
      {
        headers: {
          'Content-Type': 'application/json',
          'X-API-Key': process.env.DATAMART_API_KEY
        }
      }
    );

    return res.status(201).json(response.data);
  } catch (error) {
    console.error('DataMart API Error:', error.response?.data || error.message);
    
    return res.status(error.response?.status || 500).json({
      message: 'Failed to purchase data bundle',
      details: error.response?.data || error.message
    });
  }
}

Node.js Example:

// data-service.js
const axios = require('axios');

class DataMartService {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = 'https://datamartbackened.onrender.com/api/developer';
    this.httpClient = axios.create({
      baseURL: this.baseUrl,
      headers: {
        'Content-Type': 'application/json',
        'X-API-Key': this.apiKey
      }
    });
  }

  async purchaseData(phoneNumber, network, capacity) {
    try {
      const response = await this.httpClient.post('/purchase', {
        phoneNumber,
        network,
        capacity,
        gateway: 'wallet'
      });
      
      return response.data;
    } catch (error) {
      console.error('DataMart API Error:', error.response?.data || error.message);
      throw error;
    }
  }

  async getDataPackages(network = null) {
    try {
      const url = network ? `/data-packages?network=${network}` : '/data-packages';
      const response = await this.httpClient.get(url);
      
      return response.data;
    } catch (error) {
      console.error('Failed to fetch data packages:', error.response?.data || error.message);
      throw error;
    }
  }
}

module.exports = DataMartService;

Python Example:

# datamart_client.py
import requests

class DataMartClient:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = 'https://datamartbackened.onrender.com/api/developer'
        self.headers = {
            'Content-Type': 'application/json',
            'X-API-Key': api_key
        }
    
    def purchase_data(self, phone_number, network, capacity):
        """Purchase a data bundle for the specified phone number."""
        url = f"{self.base_url}/purchase"
        payload = {
            'phoneNumber': phone_number,
            'network': network,
            'capacity': capacity,
            'gateway': 'wallet'
        }
        
        response = requests.post(url, json=payload, headers=self.headers)
        response.raise_for_status()  # Raise exception for 4XX/5XX responses
        
        return response.json()
    
    def get_data_packages(self, network=None):
        """Get available data packages, optionally filtered by network."""
        url = f"{self.base_url}/data-packages"
        if network:
            url += f"?network={network}"
        
        response = requests.get(url, headers=self.headers)
        response.raise_for_status()
        
        return response.json()

# Usage example
if __name__ == "__main__":
    client = DataMartClient("your_api_key_here")
    
    # Get MTN data packages
    mtn_packages = client.get_data_packages("YELLO")
    print(mtn_packages)
    
    # Purchase data bundle
    result = client.purchase_data("0551234567", "TELECEL", "5")
    print(result)

For more help or support: