Skip to main content

Making Your First Request

Let's walk through making your first API request to purchase airtime.

Complete Example

Here's a complete example of purchasing R10 Vodacom airtime using different programming languages:

const axios = require("axios");

const purchaseAirtime = async () => {
try {
const response = await axios.post(
"https://api.pagamio.com/api/v1/purchase",
{
productCode: "AIR-VOD-001", // Vodacom R10 Airtime
amount: 10.0,
mobileNumber: "+27821234567",
paymentMethod: "cash",
channelId: "YOUR_CHANNEL_ID"
},
{
headers: {
Authorization: "Bearer YOUR_BEARER_TOKEN",
"Content-Type": "application/json",
},
}
);

console.log("Success:", response.data);
return response.data;
} catch (error) {
console.error("Error:", error.response.data);
throw error;
}
};

// Call the function
purchaseAirtime();

Understanding the Response

Success Response

{
"transactionId": "064b0cc0-60c9-4012-94c7-4cc095b6281e",
"responseCode": "0",
"responseMessage": "Purchase successful",
"responseDateTime": "2025-10-21T12:38:51.266157386",
"successful": true,
"receipt": {
"rechargeType": "PINLESS",
"callCentre": "082111",
"rechargeVendor": "AirtimeStub",
"amount": 1000,
"aggregator": "FLASH"
}
}

Key Response Fields:

  • transactionId - Unique identifier for the transaction
  • status - Transaction status (COMPLETED, FAILED, PENDING)
  • responseCode - Numeric code (0 = success)
  • responseMessage - Human-readable message
  • receipt - Transaction receipt details

Error Response

{
"responseCode": "1103",
"responseMessage": "Insufficient balance. Available: R0.00"
}

Common First-Time Issues

Issue 1: Invalid Phone Number Format

Error:

{
"responseCode": "1300",
"responseMessage": "Invalid phone number format"
}

Solution: Ensure phone numbers are in international format with country code:

  • ✅ Correct: +27821234567
  • ❌ Wrong: 0821234567, 27821234567

Issue 2: Missing Required Fields

Error:

{
"responseCode": "1300",
"responseMessage": "Required fields missing."
}

Solution: Verify all required fields are included:

  • productCode
  • amount
  • mobileNumber
  • paymentMethod
  • channelId

Issue 3: Invalid Product Code

Error:

{
"responseCode": "1300",
"responseMessage": "Vas Product with code AIR-VOD-0018 not found"
}

Solution: Verify the product code exists and is active. Use the Products API to get valid product codes.

Issue 4: Unauthorized

Error:

{
"responseCode": "1105",
"responseMessage": "User is not allowed to perform this action"
}

Solution: Check your Bearer token:

  • Ensure the Authorization header is correctly formatted
  • Verify the Bearer token hasn't been deactivated
  • Confirm you're using the correct environment (sandbox vs production)

Next Steps

Now that you've made your first successful request:

  1. Explore Other Products

    • Try purchasing data bundles
    • Test electricity tokens
    • Experiment with entertainment vouchers
  2. Implement Error Handling

    • Handle network failures gracefully
    • Implement retry logic for transient errors
    • Display user-friendly error messages
  3. Add Transaction History

    • Query completed transactions
    • Display receipts to users
    • Implement transaction search
  4. Set Up Webhooks

    • Receive real-time transaction updates
    • Automate receipt delivery
    • Monitor transaction status

Last updated: October 2025