# Read your wallet: credits granted, spent and remaining

- Endpoint: `GET /v1/wallet`
- Production: `https://api.main-team.org/v1/wallet`
- Sandbox: `https://apisnd.main-team.org/v1/wallet`
- Operation: `getWallet` (Wallet)
- Authentication: `Authorization: Bearer <token>`, a short-lived token you sign with your API key and secret
- Permission: `wallet/read:$org:$ID`

## Description

The wallet is not self-service: Main Team opens it only after an agreement and on your request (ask your Main Team contact or info@main-team.org), and Main Team then tells you how many credits you have for each olympiad. Without one this answers `403` `wallet_not_enabled`; bank transfer stays the default way to pay.

Your wallet holds the credits Main Team gave you, counted separately for each olympiad. A credit is a convenience: the application is marked paid at once, and the amount is still due to Main Team and settled afterwards by bank transfer. One credit pays one priced application (`createApplication` with `walletPay`, `payApplicationFromWallet`, `payApplicationsFromWallet`); a free exam never uses one.

The answer lists every olympiad, zeros included, with `granted`, `spent`, `remaining` and what the spent credits paid for in cents of that organization’s `currency` (`USD` for neo, `EUR` otherwise), plus credit `totals`. Money is never summed across currencies.

A wallet that is closed still answers, with `enabled: false`, so its history stays readable. An account that never had one answers `403` `wallet_not_enabled`.

## Response

`200` Success: `message` is "Wallet fetched successfully.".

```json
{
  "success": true,
  "message": "Wallet fetched successfully.",
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 57,
    "totalPages": 3
  },
  "data": {
    "enabled": true,
    "enabledAt": "2026-09-01T09:30:00.000Z",
    "organizations": [
      {
        "organization": "stem",
        "organizationId": "64b7f0c2a1d3e4f5a6b7c8d9",
        "currency": "EUR",
        "granted": 50,
        "spent": 9,
        "remaining": 41,
        "spentAmount": 45000
      }
    ],
    "totals": {
      "granted": 120,
      "spent": 19,
      "remaining": 101
    }
  }
}
```

## Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | [`unauthorized`](https://hub.main-team.org/api/errors#unauthorized) | The token is missing or malformed, is not signed with your account’s `apiSecret`, breaks the `iat` and `exp` rules, has expired or been revoked, or its account is not active. All of these answer the same. |
| 403 | [`forbidden`](https://hub.main-team.org/api/errors#forbidden) | The token is valid, but no role on your account allows `wallet/read` on `mto` (the target of operations without `:organizationId` in their path), or a role denies it. |
| 403 | [`forbidden`](https://hub.main-team.org/api/errors#forbidden) | Your account has no wallet, or it is closed. A wallet is not self-service: Main Team opens it only after an agreement and on your request (ask your Main Team contact or info@main-team.org). `error.details.reason` is `wallet_not_enabled`. |
| 429 | [`too_many_requests`](https://hub.main-team.org/api/errors#too_many_requests) | Your account has made more than 100 requests to this operation in the current 60-second window. Wait the seconds in `Retry-After` before sending again. |
| 500 | [`internal_error`](https://hub.main-team.org/api/errors#internal_error) | Something failed on our side. Retry later, and quote `request_id` if it goes on. |

## Code samples

### curl

```bash
# $TOKEN: a short-lived token you minted with your API key and secret
curl -sS 'https://api.main-team.org/v1/wallet' \
  -H "Authorization: Bearer $TOKEN"
```

### Node.js

```js
const token = process.env.TOKEN; // a short-lived token you minted with your API key and secret

const res = await fetch('https://api.main-team.org/v1/wallet', {
  headers: {
    Authorization: `Bearer ${token}`,
  },
});
const body = await res.json();
if (!res.ok) throw new Error(`${res.status} ${body.error.code}: ${body.error.message}`);
console.log(body.data);
```

### PHP

```php
<?php
$token = getenv('TOKEN'); // a short-lived token you minted with your API key and secret

$ch = curl_init('https://api.main-team.org/v1/wallet');
curl_setopt_array($ch, [
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $token,
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
if ($response === false) {
    throw new RuntimeException(curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$body = json_decode($response, true);
if ($status >= 400) {
    $error = $body['error'];
    throw new RuntimeException("$status {$error['code']}: {$error['message']}");
}
print_r($body['data']);
```
