> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.vtuagent.com/api-reference/vtu-agent-consumable-api/airtime/purchase-airtime/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.vtuagent.com/_mcp/server. # Purchase Airtime POST https://api.vtuagent.com/v1/airtime/purchase Content-Type: application/json Purchase airtime for a Nigerian mobile number. Your wallet is debited **immediately** and the purchase is queued to the network provider. The request then long-polls for up to **15 seconds** for the provider's result. If the provider has not answered by then you receive `202` with `status: "pending"` — the transaction is still in flight, not lost. Track it with `POST /v1/transaction/status` or via your webhook. | HTTP | `status` | `status_code` | Meaning | |---|---|---|---| | 200 | `successful` | 200 | Airtime delivered | | 202 | `pending` | 202 | Still processing after 15 s | | 400 | `error` | — | Bad payload, validation failure, insufficient balance, or duplicate `request_ref` | | 401 | — | — | Missing, invalid or revoked API key | | 424 | `failed` | 424 | Provider rejected the purchase — wallet already refunded | | 500 | `error` | — | Internal error; wallet is rolled back | **Webhook events:** `airtime.purchase.success`, `airtime.purchase.failed`, `airtime.purchase.pending`. Reference: https://docs.vtuagent.com/api-reference/vtu-agent-consumable-api/airtime/purchase-airtime ## Authentication - `Authorization` header (bearer token, required) — API key issued from the VTUAgent dashboard, sent as `Authorization: Bearer {your_api_key}`. ## Request ### Body (application/json) This endpoint expects an AirtimePurchaseRequest. - `network` (enum, required) — Provider service ID, forwarded verbatim. - Allowed values: `mtn`, `glo`, `airtel`, `etisalat` - `phone` (string, required) — Recipient number in local format. - `amount` (AirtimePurchaseRequestAmount, required) — Naira. Accepted as a JSON number or a numeric string; always returned as a string. - `request_ref` (string, required) — Your unique reference for this transaction, max 50 characters. A UUID is recommended. Re-using one is rejected with 400. ## Response ### 200 Airtime delivered - `status` (enum, required) - Allowed values: `successful`, `pending`, `failed` - `status_code` (enum, required) — Always equals the HTTP status. - Allowed values: `200`, `202`, `424` - `message` (string, required) - `reference` (string, optional) — Echo of your request_ref. - `data` (map from string to any, optional) — Product-specific details; see the endpoint examples. ### 202 Still processing after 15 s — poll `/v1/transaction/status` - `status` (enum, required) - Allowed values: `successful`, `pending`, `failed` - `status_code` (enum, required) — Always equals the HTTP status. - Allowed values: `200`, `202`, `424` - `message` (string, required) - `reference` (string, optional) — Echo of your request_ref. - `data` (map from string to any, optional) — Product-specific details; see the endpoint examples. ## Errors ### 400 Bad Request Error Invalid payload, validation error, insufficient balance, or duplicate request_ref - `status` (enum, required) - Allowed values: `error` - `message` (string, required) - `error` (string, optional) — Validator detail, present only on validation failures. ### 401 Unauthorized Error Missing, invalid or revoked API key. Note: this envelope has no `status` field. - `message` (string, required) - `error` (string, required) ### 424 Failed Dependency Error Provider rejected the purchase — wallet refunded - `status` (enum, required) - Allowed values: `successful`, `pending`, `failed` - `status_code` (enum, required) — Always equals the HTTP status. - Allowed values: `200`, `202`, `424` - `message` (string, required) - `reference` (string, optional) — Echo of your request_ref. - `data` (map from string to any, optional) — Product-specific details; see the endpoint examples. ### 500 Internal Server Error Internal error - `status` (enum, required) - Allowed values: `error` - `message` (string, required) - `error` (string, optional) — Validator detail, present only on validation failures. ## Types ### AirtimePurchaseRequestAmount Naira. Accepted as a JSON number or a numeric string; always returned as a string. ## Examples **Request** ```json { "network": "mtn", "phone": "08012345678", "amount": 100, "request_ref": "9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70" } ``` **Response** ```json { "status": "successful", "status_code": 200, "message": "Airtime purchase successful - 100 to 08012345678", "reference": "9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70", "data": { "amount": "100", "network": "mtn", "phone": "08012345678" } } ``` **SDK Code** ```python import requests url = "https://api.vtuagent.com/v1/airtime/purchase" payload = { "network": "mtn", "phone": "08012345678", "amount": 100, "request_ref": "9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70" } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.vtuagent.com/v1/airtime/purchase'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"network":"mtn","phone":"08012345678","amount":100,"request_ref":"9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.vtuagent.com/v1/airtime/purchase" payload := strings.NewReader("{\n \"network\": \"mtn\",\n \"phone\": \"08012345678\",\n \"amount\": 100,\n \"request_ref\": \"9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.vtuagent.com/v1/airtime/purchase") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"network\": \"mtn\",\n \"phone\": \"08012345678\",\n \"amount\": 100,\n \"request_ref\": \"9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.vtuagent.com/v1/airtime/purchase") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"network\": \"mtn\",\n \"phone\": \"08012345678\",\n \"amount\": 100,\n \"request_ref\": \"9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70\"\n}") .asString(); ``` ```php request('POST', 'https://api.vtuagent.com/v1/airtime/purchase', [ 'body' => '{ "network": "mtn", "phone": "08012345678", "amount": 100, "request_ref": "9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70" }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.vtuagent.com/v1/airtime/purchase"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"network\": \"mtn\",\n \"phone\": \"08012345678\",\n \"amount\": 100,\n \"request_ref\": \"9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "network": "mtn", "phone": "08012345678", "amount": 100, "request_ref": "9f1c2a4e-7b3d-4c8e-9a1f-2b3c4d5e6f70" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.vtuagent.com/v1/airtime/purchase")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```