Use the API in Postman

Import the Astrada API and the Banking API into Postman as two collections, get tokens with one script, and set up sandbox and production environments.

For: developers

The Astrada API is published as two OpenAPI definitions. Postman imports each one as a collection, with a request for every operation in the API reference. The collections are generated from the same definitions as the reference, so there is no hand-kept collection to fall out of date.

This page is about calling the API by hand in Postman, which is separate from the Backend SDKs for server code.

The two definitions

Astrada API

https://docs.astrada.co/openapi/astrada-api.json

Subaccounts, webhooks, card subscriptions, card verifications, cards and cardholders, transactions and transaction messages, network bulk feeds and bulk enrollments, enrollment methods, enrollment links, BIN lookup, and the sandbox simulations.

Astrada Banking API

https://docs.astrada.co/openapi/astrada-banking.json

Bank links, bank accounts, bank subscriptions, bank transactions and transaction matches.

Import both to cover the whole API. The banking requests are only in the Astrada Banking API collection.

Both definitions are published again with every API release, and Postman builds the collection from the definition when you import it, so there is no collection file to download or keep up to date. To pick up changes after a release, import the address again and add the token script (below) to the new collection. Importing again gives you a new collection: anything you saved in the old one stays there, so copy over what you need and then delete it. The environment and its values are not changed.

Import the definitions

  1. Copy the address of a definition from above. To work from a file instead, open any page of that definition in the API reference and use the download icon beside its title.
  2. In Postman, open Import and paste the address (or choose the file).
  3. Repeat for the other definition.

Each collection has a folder per part of the API path (for example subaccounts, webhooks, bank-links), and each request is named after its summary in the API reference. Every request starts on {{baseUrl}}, a collection variable set to https://api.sandbox.astrada.co, the only server the definitions name.

Before you send a request:

  • Every query parameter comes switched on, holding a placeholder such as <string> or <uuid>, or a sample value. Fill in the required ones (their description starts "(Required)") and switch off the optional ones you do not want. A placeholder sent as it is can get a 400 (cursor=<string> does), and a sample value can filter the results: List cards comes with a sample country, so it may return only that country's cards.
  • Path variables start as a placeholder such as <uuid>, or as a made-up value that looks like a real ID (bankLinkId on the bank link requests). Fill them in.
  • Request bodies are filled from the schema, with placeholders such as "<string>" and "<integer>" and made-up values, not the examples in the API reference. Replace them with your own: a placeholder in quotes is sent as a string, even in a number field.

Set up an environment

Create one Postman environment per Astrada environment, with these variables. Both collections use the same environment.

VariableValue
baseUrlhttps://api.sandbox.astrada.co for the sandbox, https://api.astrada.co for production
accountIdYour account ID
clientIdYour client ID (in production, the API client ID)
clientSecretYour client secret (in production, the API client secret)

Start with the sandbox: sign up at astrada.co/sandbox for an account ID, client ID and client secret (Get a token shows the same token call with curl). In production, use the API credentials, not the SDK credentials (Authentication explains the two sets).

The environment's baseUrl takes the place of the collection's, so choosing the environment in Postman's environment selector is how you switch between sandbox and production.

🚧

Keep secrets local

Keep clientSecret as a local value. A value you share is synced to Postman's cloud and to everyone in the workspace. Never put production credentials in a shared workspace or a shared value.

Get a token for every request

Every request needs an OAuth 2.0 bearer token from the client credentials flow (Authentication). Tokens last 5 minutes. Add this script once to each collection, on the collection's Scripts tab under Pre-request. It runs before every request in the collection: it gets a token from {{baseUrl}}/auth/realms/{{accountId}}/protocol/openid-connect/token, keeps it in the environment until 30 seconds before it expires, and sends the request with it as a bearer token.

const tokenUrl = pm.variables.get("baseUrl") + "/auth/realms/" +
  pm.variables.get("accountId") + "/protocol/openid-connect/token";
const tokenFor = tokenUrl + " " + pm.variables.get("clientId");
const token = pm.environment.get("accessToken");
const expiresAt = Number(pm.environment.get("accessTokenExpiresAt") || 0);

function useToken(value) {
  pm.request.authorizeUsing("bearer", { token: value });
}

if (token && pm.environment.get("accessTokenFor") === tokenFor &&
    Date.now() < expiresAt - 30000) {
  useToken(token);
} else {
  pm.sendRequest({
    url: tokenUrl,
    method: "POST",
    body: {
      mode: "urlencoded",
      urlencoded: [
        { key: "grant_type", value: "client_credentials" },
        { key: "client_id", value: pm.variables.get("clientId") },
        { key: "client_secret", value: pm.variables.get("clientSecret") },
      ],
    },
  }, (err, res) => {
    if (err || res.code !== 200) {
      const reason = err ? err.message || JSON.stringify(err)
        : res.code + " " + res.status + " " + res.text();
      console.error("Token request failed: " + reason);
      return;
    }
    const body = res.json();
    pm.environment.set("accessToken", body.access_token);
    pm.environment.set("accessTokenFor", tokenFor);
    pm.environment.set("accessTokenExpiresAt", Date.now() + body.expires_in * 1000);
    useToken(body.access_token);
  });
}

The script replaces the OAuth 2.0 settings each imported request carries, so you do not need to change any request. Those settings list every scope in the definition and keep {accountId} in the token address as written, and the sandbox refuses a token request for all of those scopes with invalid_scope. The script asks for no scope; in the sandbox the token then carries the client's scopes, banking:admin and simulation:write among them. If the token request is refused (a wrong secret, for example), the script writes the status and the reason to the console and the request goes out without a token, so it answers 401. The script fetches a new token when baseUrl, accountId or clientId changes.

Scopes

A sandbox client holds every sandbox scope, including banking:read, banking:write, banking:admin and simulation:write. Production clients hold the scopes Astrada sets up for your account. In the banking collection, requests whose names start with "Needs banking:admin:" need banking:admin, and every bank subscription read is one of them. The other reads need banking:read and the other requests need banking:write. The token's issuer carries your account ID, so there is no separate account header.

Sandbox-only requests

These requests exist only in the sandbox; their names end in "(sandbox only)":

  • The deletes that clear test data, such as Delete subaccount and Delete card subscription.
  • The seven requests in the simulate folder, which simulate transactions, transaction messages and network bulk files.

The two bank deletes in the banking collection also exist in production, where they cannot be undone, so check which environment is selected before you send one.

Try it

With the sandbox environment selected, send "List subaccounts" from the Astrada API collection, then "List bank links" from the Astrada Banking API collection. Switch off each query parameter that holds a placeholder first (cursor on the first, subaccountId and cursor on the second). Both answer 200.


Did this page help you?