# Reading your balance

> Check what your organization can spend before you order, and read a campaign budget by its ID.


An order is paid for from your On Me balance, so the question before any `POST /v1/orders` is whether there is enough in it. `GET /v1/balance` answers that for your organization, and takes an optional `campaign_id` to report a campaign's budget instead.

`GET /v1/balance` ([API reference](https://business.onme.com/docs/reference#tag/balance/GET/v1/balance))

## Your organization balance

Send the request with no parameters:

**cURL**

```bash
curl https://api.onme.com/v1/balance \
  -H "Authorization: Bearer $ONME_API_KEY"
```
**Node**

```js
const response = await fetch('https://api.onme.com/v1/balance', {
  headers: { Authorization: `Bearer ${process.env.ONME_API_KEY}` },
})
const balance = await response.json()
if (balance.spendable < orderTotal) {
  throw new Error('Top up before ordering')
}
```
**Python**

```python
import os
import requests

response = requests.get(
    "https://api.onme.com/v1/balance",
    headers={"Authorization": f"Bearer {os.environ['ONME_API_KEY']}"},
)
balance = response.json()
if balance["spendable"] < order_total:
    raise RuntimeError("Top up before ordering")
```

**200 OK**
```json
{
  "scope": "organization",
  "spendable": 125000
}
```

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `scope` | string | Yes | Whose funds `spendable` describes. `campaign` only when the campaign you asked for has a budget of its own; otherwise it spends the organization balance and this reads `organization`. (enum: organization \| campaign) |
| `spendable` | integer | Yes | The most an order may draw from this balance right now, in cents. An order whose total exceeds it is refused. Negative means that much must be added before anything can be sent. |

`spendable` is an integer in US cents, so `125000` is $1,250.00. It is the whole answer: an order whose total exceeds it comes back [`insufficient_balance`](https://business.onme.com/docs/reference#errors/insufficient_balance), with nothing created and nothing charged. It can be negative, which means that much has to be added before anything at all can be sent.

An organization that has never added funds gets zero, not an error. There is nothing wrong; there is simply no money yet.

Add funds under [Billing](https://business.onme.com/billing) in the business portal. There is no API for topping up, and the fuller picture — what you have added, what you have spent, and anything still clearing — lives there too.

## A campaign's budget

Campaigns are created in the business portal, and a campaign can be given a budget of its own. Pass its ID to read that budget instead:

```bash
curl "https://api.onme.com/v1/balance?campaign_id=ocp-7mJ0fQ2a" \
  -H "Authorization: Bearer $ONME_API_KEY"
```

**200 OK**
```json
{
  "scope": "campaign",
  "spendable": 30000
}
```

**Not every campaign has a budget of its own.** One that doesn't spends the organization balance directly, so that is what comes back — `scope` reads `organization` and `spendable` is your organization's:

**200 OK**
```json
{
  "scope": "organization",
  "spendable": 125000
}
```

Read `scope` to know whose money the figure is, rather than assuming a `campaign_id` in the request means a campaign in the response.

A campaign ID we don't recognise — including one belonging to another organization, and a value that isn't shaped like an ID at all — is a `422` with [`parameter_invalid`](https://business.onme.com/docs/reference#errors/parameter_invalid) naming `campaign_id`. `POST /v1/orders` answers the same way for the same ID.

## In the sandbox

`GET /v1/balance` works the same way with a sandbox key, against your sandbox funds. Those are credited without a card being charged, and a [sandbox reset](https://business.onme.com/docs/sandbox#starting-over) deletes them — after which the endpoint reports zero again. A reset clears campaign budgets too, so a campaign that had one reads back as spending the organization balance until you give it another.
