Electricity Purchase Endpoint

Endpoint

URL: /api/electricapi

Methods: POST, GET

Description

This API endpoint allows users to purchase electric credits.

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)

  • number (string, required): The meter number to recharge.
  • firstLevel (string, required): The electricity disco.
  • secondLevel (string, required): The type of meter, prepaid or postpaid.
  • amount (number, required): The amount to purchase.

Usage Example

See usage example in the code snippets below:

Example: Purchase Electricity

POST request to purchase electricity:


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

{
"number": "0000000000",
"firstLevel": "IKEDC",
"secoondLevel": "prepaid",
"amount": 1000
}
      

Response:


- Status Code: 200

{
"message": "Transaction successful",
"electricHistory": {
"transactionId": "1234567890",
"email": "user@example.com",
"activity": "IKEDC",
"message": "prepaid",
"status": "Success",
"recipient": "0000000000",
"token": "12234323464565434",
"unit": "11110",
"amount": 1000,
"amountUsed": 990,
"initialBalance": 5000,
"finalBalance": 4010
"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",
"electricHistory": {
"transactionId": "1234567890",
"email": "user@example.com",
"activity": "IKEDC",
"message": "prepaid",
"status": "Failed",
"recipient": "0000000000",
"amount": 1000,
"initialBalance": 5000,
"finalBalance": 5000
"Method": API,
}
}
    

GET request

See usage example in the code snippets below:

Get the list of available firstLevel and secondLevel

GET request for available firstLevel and secondLevel:


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

      

Response:


- Status Code: 200

{
    "IKEDC": {
        "available": true,
        "secondLevel": [
            "prepaid",
            "postpaid"
        ],
        "amount": [
            100,
            100
        ]
    }
}
- The `amount` field represents the percentage of the actual amount deducted from the user's balance based on user level.

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.