> 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/data/purchase-data-bundle/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.vtuagent.com/_mcp/server. # Purchase Data Bundle POST https://api.vtuagent.com/v1/data/purchase Content-Type: application/json Purchase a mobile data bundle using a `plan_id` from `GET /v1/data/plans`. The amount is taken from your account-tier price — you do not send it. Your wallet is debited **immediately** and the purchase is queued. The request long-polls for up to **15 seconds**; if the provider has not answered you receive `202` with `status: "pending"`. Track it with `POST /v1/transaction/status` or via your webhook. | HTTP | `status` | `status_code` | Meaning | |---|---|---|---| | 200 | `successful` | 200 | Bundle delivered | | 202 | `pending` | 202 | Still processing after 15 s | | 400 | `error` | — | Bad payload, unknown/unsupported plan, 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:** `data.purchase.success`, `data.purchase.failed` (none while pending). Reference: https://docs.vtuagent.com/api-reference/vtu-agent-consumable-api/data/purchase-data-bundle ## 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 a DataPurchaseRequest. - `plan_id` (string, required) — From GET /v1/data/plans. - `phone` (string, required) - `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 Bundle 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, unknown plan, 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. ## Examples **Request** ```json { "plan_id": "mtn_1gb_30d", "phone": "08012345678", "request_ref": "3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d" } ``` **Response** ```json { "status": "successful", "status_code": 200, "message": "Data purchase successful - MTN 1GB (SME) for 08012345678", "reference": "3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d", "data": { "amount": "270", "phone": "08012345678", "plan": "MTN 1GB (SME)" } } ``` **SDK Code** ```python import requests url = "https://api.vtuagent.com/v1/data/purchase" payload = { "plan_id": "mtn_1gb_30d", "phone": "08012345678", "request_ref": "3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d" } 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/data/purchase'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"plan_id":"mtn_1gb_30d","phone":"08012345678","request_ref":"3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d"}' }; 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/data/purchase" payload := strings.NewReader("{\n \"plan_id\": \"mtn_1gb_30d\",\n \"phone\": \"08012345678\",\n \"request_ref\": \"3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d\"\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/data/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 \"plan_id\": \"mtn_1gb_30d\",\n \"phone\": \"08012345678\",\n \"request_ref\": \"3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d\"\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/data/purchase") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"plan_id\": \"mtn_1gb_30d\",\n \"phone\": \"08012345678\",\n \"request_ref\": \"3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d\"\n}") .asString(); ``` ```php request('POST', 'https://api.vtuagent.com/v1/data/purchase', [ 'body' => '{ "plan_id": "mtn_1gb_30d", "phone": "08012345678", "request_ref": "3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d" }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.vtuagent.com/v1/data/purchase"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"plan_id\": \"mtn_1gb_30d\",\n \"phone\": \"08012345678\",\n \"request_ref\": \"3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "plan_id": "mtn_1gb_30d", "phone": "08012345678", "request_ref": "3c9e7d22-5a1b-4f6e-8d2c-1e2f3a4b5c6d" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.vtuagent.com/v1/data/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() ```