# Postman

The generated Postman collection and environments, with smoke folders for a customer key and an operator key.

A Postman collection is generated from the same contract as this portal, so every operation an API key can call is in it, customer level and operator level. It lives in the repository at `docs/api/postman/` and is regenerated with each contract release; do not edit it by hand.

| File                                            | What                                                               |
| ----------------------------------------------- | ------------------------------------------------------------------ |
| `wirebloom.postman_collection.json`             | the collection (Postman v2.1), one folder per resource             |
| `wirebloom-local.postman_environment.json`      | `baseUrl` `http://localhost:3001/v1`                               |
| `wirebloom-staging.postman_environment.json`    | `baseUrl` `https://api.staging.banking.wirebloom.com/v1` (sandbox) |
| `wirebloom-production.postman_environment.json` | `baseUrl` `https://api.banking.wirebloom.com/v1`                   |

## Import

1. In Postman choose **Import** and select the collection file and the environment you want (start with staging).
2. Select the environment in the top-right environment picker.
3. Fill the variables of the environment. Keep keys in the **current value** column only, so they stay on your machine and are never synced or exported:

| Variable         | Value                                                           |
| ---------------- | --------------------------------------------------------------- |
| `apiKey`         | a customer-level key (`wb_test_…` on staging), type secret      |
| `tenantId`       | the customer id that key belongs to                             |
| `operatorApiKey` | an operator-level key, type secret (only for operator requests) |
| `operatorId`     | the operator id                                                 |
| `webhookSecret`  | an endpoint secret, type secret, if you test webhook signatures |

Every request sends `Authorization: Bearer {{apiKey}}` and `X-Tenant-Id: {{tenantId}}`. Requests for operator operations live in folders named `operator: …` and send `{{operatorApiKey}}` and `{{operatorId}}` instead, so one environment serves both levels.

## Folders

- **Smoke**: a handful of read calls for a customer key. Each asserts `200`, the page envelope (`data`, `page`) and an `X-Request-Id` header.
- **Operator smoke**: the same for an operator key.
- One folder per resource (balances, payments, recipients, exchanges, transactions, integrator webhooks, simulations and more), and `operator: …` folders for the operator API.

Bodies come from the contract examples. Requests whose operation accepts `Idempotency-Key` send `{{$guid}}`, a fresh UUID per send: to retry a request safely, copy the key of the first send into the header instead.

## Run the smoke folders

In Postman: open the collection, choose **Run**, pick the **Smoke** folder and the staging environment.

From the command line with newman:

```sh
npm install -g newman
cd docs/api/postman
newman run wirebloom.postman_collection.json \
  -e wirebloom-staging.postman_environment.json \
  --env-var "apiKey=$WIREBLOOM_API_KEY" \
  --env-var "tenantId=$WIREBLOOM_CUSTOMER_ID" \
  --folder Smoke
```

For the operator folder pass `operatorApiKey` and `operatorId` and `--folder "Operator smoke"`. Passing keys with `--env-var` from your shell keeps them out of the environment file.

## Simulate events in the sandbox

With the staging environment and a `wb_test_` key, the `simulations` folder drives the sandbox bank: credit a balance with an incoming payment, move a payment to `completed` or `returned`, move an FX rate or send any webhook event to your endpoints. Simulations answer `202` and take effect within seconds ([Sandbox and simulation](/docs/sandbox)). Live keys get `403`.

## Scopes and errors

Postman only sends what you ask; the API decides by scope and key level:

- `403` [`insufficient-scope`](/errors#insufficient-scope): the key lacks the scope the operation lists, or it is the wrong key level (a customer key on an operator request or the reverse). The [scope catalogue](/scopes) shows what each scope reaches.
- `403` for an operation listed under [session-only operations](/session-only): no key can call it.
- `401` [`invalid-api-key`](/errors#invalid-api-key): an unknown, revoked or expired key, or a `wb_test_` key outside the sandbox.
- `428` on an update: send `If-Match` with the `ETag` of your last read.

Quote the `requestId` of a problem response when you contact support.

## Keep it current

The collection's `contractVersion` variable names the contract it was generated from. When the [changelog](/changelog) announces a new contract version, import the collection again; environments can stay.

## Next

- [SDKs](/docs/sdks) for code instead of clicks.
- The [customer walkthrough](/docs/customer-walkthrough) and the [operator walkthrough](/docs/operator-walkthrough) use the same calls as the smoke folders.
