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

# Backend API

> Read your users' private balances and track shield and unshield requests from your own server

# Backend API

Privacy Boost serves a small HTTP API for your own backend. Use it to read the private balances of users who signed in through your app, and to check whether a shield or unshield they submitted has settled. It authenticates with your app's client credentials. There is no SDK for it; call it with any HTTP client.

| Method | Path | Returns |
| - | - | - |
| `POST` | `/api/v1/server/balances` | One user's available private balances |
| `GET` | `/api/v1/server/balances` | A page of your app's users and their balances |
| `GET` | `/api/v1/server/requests/{requestId}` | The outcome of a shield or unshield |

> [!WARNING]
>
> These routes run over plain HTTPS. They don't use the encrypted transport the SDKs use, and the client secret goes out with every request. Call them only from servers you control, and never ship the client secret in a browser bundle, a mobile app, or anything else that runs on a user's device.

## Base URL

Each network has its own server. Send requests to the `serverUrl` of the network you want from [Supported Networks](https://docs.privacyboost.io/sdk/concepts/configuration.md#supported-networks), for example `https://optimism.privacyboost.io` for OP Mainnet. Balances belong to that server's chain, and balance responses include its `chainId`.

## Authentication

The API takes the client ID and client secret of an app set up for the `api_secret` auth method. The Privacy Boost team issues them when it configures your app; see [App Setup](https://docs.privacyboost.io/sdk/concepts/app-setup.md) and [API Secret](https://docs.privacyboost.io/sdk/guides/api-secret.md).

Send the pair with HTTP Basic authentication: the client ID is the username and the client secret is the password. The server doesn't accept credentials in the URL or the request body.

```bash theme={null}
export PRIVACY_BOOST_SERVER_URL=https://optimism.privacyboost.io
export PRIVACY_BOOST_CLIENT_ID="pk_live_..."
export PRIVACY_BOOST_CLIENT_SECRET="sk_live_..."

curl -u "$PRIVACY_BOOST_CLIENT_ID:$PRIVACY_BOOST_CLIENT_SECRET" \
  "$PRIVACY_BOOST_SERVER_URL/api/v1/server/balances?limit=1"
```

The credential decides which app the request acts for, and a request can't name a different one. A missing or wrong credential gets `401 UNAUTHORIZED` with a `WWW-Authenticate: Basic` header. So does a revoked or expired credential, a suspended app, or an app whose `api_secret` method is turned off. A revoked credential can keep working for up to a minute after revocation.

Every response carries `Cache-Control: no-store`.

## Get One User's Balances

`POST /api/v1/server/balances` returns the available balances of one user of your app. The body is a single JSON object with one field, and any other field is rejected.

| Field | Type | Description |
| - | - | - |
| `owner_wallet_address` | `string` | The Ethereum address the user signs in with. Any letter case |

```bash theme={null}
curl -u "$PRIVACY_BOOST_CLIENT_ID:$PRIVACY_BOOST_CLIENT_SECRET" \
  -H 'Content-Type: application/json' \
  -d '{"owner_wallet_address":"0x1111111111111111111111111111111111111111"}' \
  "$PRIVACY_BOOST_SERVER_URL/api/v1/server/balances"
```

```json theme={null}
{
  "ownerWalletAddress": "0x1111111111111111111111111111111111111111",
  "privacyAddress": "0x1d0c...e94b",
  "chainId": 10,
  "balances": [
    {
      "tokenAddress": "0x2222222222222222222222222222222222222222",
      "symbol": "USDC",
      "decimals": 6,
      "balance": "2500000"
    }
  ]
}
```

The request field is snake\_case and the response fields are camelCase.

| Field | Type | Description |
| - | - | - |
| `ownerWalletAddress` | `string` | The wallet address, checksummed |
| `privacyAddress` | `string` | The user's privacy address |
| `chainId` | `number` | Chain the balances are on |
| `balances` | `array` | One entry per token with a positive balance. Empty when the user holds nothing |
| `balances[].tokenAddress` | `string` | Token contract address |
| `balances[].symbol` | `string` | Token symbol |
| `balances[].decimals` | `number` | Token decimals. Omitted when the server has no metadata for the token |
| `balances[].balance` | `string` | Available balance in the token's base units, as a decimal string |

The balance is what the user can spend now: confirmed plus preconfirmed notes.

If the wallet isn't a user of your app, or has no privacy account registered on this chain, the server answers `404 NOT_FOUND`. Both cases get the same response, so the endpoint never shows whether a wallet uses some other app. Only wallets that signed in through your app are visible.

## List Your Users' Balances

`GET /api/v1/server/balances` pages through every user of your app, in the order they first signed in, with each user's balances.

| Parameter | Type | Description |
| - | - | - |
| `limit` | `integer` | Users per page, from 1 to 200. Default `100` |
| `cursor` | `string` | The `nextCursor` from the previous page. Leave it out for the first page |

Any other query parameter, or either of these given twice or empty, returns `400 INVALID_PARAMETER`.

```bash theme={null}
# First page
curl -u "$PRIVACY_BOOST_CLIENT_ID:$PRIVACY_BOOST_CLIENT_SECRET" \
  "$PRIVACY_BOOST_SERVER_URL/api/v1/server/balances?limit=200"

# Next page: pass the previous nextCursor back as cursor
curl -u "$PRIVACY_BOOST_CLIENT_ID:$PRIVACY_BOOST_CLIENT_SECRET" \
  --get --data-urlencode "cursor=$NEXT_CURSOR" --data-urlencode "limit=200" \
  "$PRIVACY_BOOST_SERVER_URL/api/v1/server/balances"
```

```json theme={null}
{
  "chainId": 10,
  "users": [
    {
      "ownerWalletAddress": "0x1111111111111111111111111111111111111111",
      "privacyAddress": "0x1d0c...e94b",
      "balances": [
        {
          "tokenAddress": "0x2222222222222222222222222222222222222222",
          "symbol": "USDC",
          "decimals": 6,
          "balance": "2500000"
        }
      ]
    },
    {
      "ownerWalletAddress": "0x3333333333333333333333333333333333333333",
      "privacyAddress": null,
      "balances": null
    }
  ],
  "nextCursor": "eyJhZnRlciI6MjAw...Qk3x"
}
```

| Field | Type | Description |
| - | - | - |
| `chainId` | `number` | Chain the balances are on |
| `users` | `array` | Up to `limit` users |
| `users[].ownerWalletAddress` | `string` | The wallet address, checksummed |
| `users[].privacyAddress` | `string \| null` | The user's privacy address. `null` until the user's privacy keys are set up |
| `users[].balances` | `array \| null` | Entries shaped like the single-user response. `[]` when the user has a registered account on this chain and nothing available; `null` when there is no registered account on this chain |
| `nextCursor` | `string` | Present when more users remain. Absent on the last page |

Keep passing `nextCursor` back as `cursor` until a response has none. The cursor is opaque and works only with your app's credentials on the same network. It expires 24 hours after the first page of the run, so a full listing has to finish within that window. An expired or altered cursor returns `400 INVALID_PARAMETER`; start again without one.

The set of users is fixed when the first page is read. Users who sign in after that show up in your next run. Balances are read as each page is served, so a full listing isn't a snapshot of a single moment.

## Track a Shield or Unshield

`GET /api/v1/server/requests/{requestId}` returns the status of a shield or unshield that one of your users submitted. Your client gets the ID from the SDK and passes it to your backend.

| Request | `requestId` format | Where it comes from |
| - | - | - |
| Shield | On-chain shield request ID, in decimal or `0x` hex | `requestId` on the SDK's shield result (`request_id` in the CLI's JSON output) |
| Unshield | UUID | `requestId` on the SDK's unshield result (`request_id` in the CLI's JSON output) |

```bash theme={null}
curl -u "$PRIVACY_BOOST_CLIENT_ID:$PRIVACY_BOOST_CLIENT_SECRET" \
  "$PRIVACY_BOOST_SERVER_URL/api/v1/server/requests/12345"
```

```json theme={null}
{
  "id": "12345",
  "type": "shield",
  "status": "approved",
  "txHash": "0x9f2c...41d7"
}
```

| Field | Type | Description |
| - | - | - |
| `id` | `string` | The request ID. Shield IDs come back in decimal |
| `type` | `string` | `shield` or `unshield` |
| `status` | `string` | One of the statuses below |
| `txHash` | `string` | The transaction that settles the request. It can appear while the status is still `pending`, once that transaction is submitted. Omitted before then |

| Status | Type | Meaning |
| - | - | - |
| `pending` | Both | Not settled yet. A preconfirmed shield still reads `pending` |
| `approved` | Shield | The shield settled on-chain |
| `rejected` | Shield | The shield failed |
| `completed` | Unshield | The unshield settled on-chain |
| `failed` | Unshield | The unshield failed |

Poll until the status is no longer `pending`. Every other status is final unless an L2 reorg drops the block that settled it. The response carries no error text for a failed request.

An unknown shield ID returns `404 SHIELD_NOT_FOUND` and an unknown unshield ID returns `404 TRANSFER_NOT_FOUND`. Private transfers and other request types share the ID space with unshields, and their IDs get the same `404 TRANSFER_NOT_FOUND`. An ID that is neither a number nor a UUID returns `400 INVALID_PARAMETER`.

## Errors

Errors come back in this JSON shape:

```json theme={null}
{
  "error": {
    "type": "RATE_LIMIT",
    "code": "RATE_LIMITED",
    "message": "Too many requests",
    "retryable": true,
    "details": {
      "request_id": "req_6f0d4b2a9c81e37a5b10c4d2",
      "retry_after_ms": 60000
    }
  },
  "status": 429
}
```

Branch on `code`. `details.request_id` matches the `X-Request-ID` response header; include it when you report a problem to the Privacy Boost team.

| HTTP | `code` | When |
| - | - | - |
| 400 | `INVALID_REQUEST` | The `POST` body isn't a single JSON object holding only `owner_wallet_address` |
| 400 | `INVALID_PARAMETER` | An invalid address, `limit`, query parameter, cursor, or request ID |
| 401 | `UNAUTHORIZED` | Missing or invalid credentials |
| 404 | `NOT_FOUND` | Balance lookup: the wallet isn't a user of your app on this chain |
| 404 | `SHIELD_NOT_FOUND`, `TRANSFER_NOT_FOUND` | Status lookup: no shield or unshield with that ID |
| 429 | `RATE_LIMITED` | Over a rate limit |
| 500 | `INTERNAL_ERROR` | The status lookup failed on the server |
| 503 | `SERVICE_UNAVAILABLE` | A server dependency is temporarily unavailable |

`retryable` is `true` for `429` and `503`. Retry those after a delay, and fix the request before retrying a `4xx`.

## Rate Limits

Every route counts against the server's per-IP read limit. The limit is checked before the credential, so failed authentication attempts use it up too. Status lookups also count against a second limit, shared by every request made with your app's credentials. A request over either limit gets `429 RATE_LIMITED` with a `Retry-After` header and `details.retry_after_ms`. Wait at least that long before you retry.

## Next Steps

* [API Secret](https://docs.privacyboost.io/sdk/guides/api-secret.md) covers getting, rotating, and storing client credentials
* [Transaction Lifecycle](https://docs.privacyboost.io/sdk/concepts/transaction-lifecycle.md) explains the states a request moves through
* [Supported Networks](https://docs.privacyboost.io/sdk/concepts/configuration.md#supported-networks) lists each network's server URL


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.