> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dojah.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Buy Data

> Purchase a mobile data bundle for any number using a plan code from the Data Plans endpoint.

<div className="dj-endpoint">
  <span className={`dj-method dj-method-post`}>POST</span>
  <code>/api/v1/purchase/data</code>
</div>

Purchase a mobile data bundle for any number. Pick a bundle with its plan code from the Data Plans endpoint, then pass that code here.

## Headers

| Header          | Required | Description                                         |
| --------------- | -------- | --------------------------------------------------- |
| `Authorization` | Yes      | Your app's secret key, sent as-is — *not* `Bearer`. |
| `AppId`         | Yes      | The App ID from your dashboard.                     |
| `Content-Type`  | Yes      | `application/json`                                  |

## Body parameters

| Parameter     | Type   | Required | Description                                                                                                              |
| ------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------ |
| `plan`        | string | Yes      | The bundle's plan code, e.g. `9MOBILE_1.5GB`. Get valid codes from [Data Plans](/api-reference/airtime-data/data-plans). |
| `destination` | number | Yes      | The mobile number to receive the data, e.g. `2348012345678`.                                                             |

## Response

Returns an `entity` with the `phone_number` credited, the `amount` charged, the `network` and bundle description, and a `reference_id` for the transaction.

## Errors

| Code  | Meaning                                                                                       |
| ----- | --------------------------------------------------------------------------------------------- |
| `400` | Bad request — a required field is missing or malformed.                                       |
| `401` | Unauthorized — check your key and `AppId` (no `Bearer` prefix).                               |
| `402` | Insufficient wallet balance. [Fund your wallet](/api-reference/core-concepts/wallet-billing). |
| `429` | Too many requests — back off and retry.                                                       |

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.dojah.io/api/v1/purchase/data" \
    -H "Authorization: {{secret_key}}" \
    -H "AppId: {{app_id}}" \
    -H "Content-Type: application/json" \
    -d '{
      "plan": "9MOBILE_1.5GB",
      "destination": 2348012345678
    }'
  ```

  ```js Node.js theme={null}
  const res = await fetch("https://api.dojah.io/api/v1/purchase/data", {
    method: "POST",
    headers: {
      Authorization: process.env.DOJAH_SECRET_KEY,
      AppId: process.env.DOJAH_APP_ID,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      plan: "9MOBILE_1.5GB",
      destination: 2348012345678,
    }),
  });
  const data = await res.json();
  ```

  ```python Python theme={null}
  import os, requests

  res = requests.post(
      "https://api.dojah.io/api/v1/purchase/data",
      headers={
          "Authorization": os.environ["DOJAH_SECRET_KEY"],
          "AppId": os.environ["DOJAH_APP_ID"],
      },
      json={
          "plan": "9MOBILE_1.5GB",
          "destination": 2348012345678,
      },
  )
  data = res.json()
  ```
</RequestExample>

<ResponseExample>
  ```json POST /api/v1/purchase/data theme={null}
  {
    "entity": {
      "phone_number": "2348012345678",
      "amount": 200,
      "network": "MTN 200 MB DATA BUNDLE",
      "reference_id": "dj_e076726b-b136-4e18-b63d-3eabc77d56c1"
    }
  }
  ```
</ResponseExample>
