{
  "info": {
    "name": "MagniFinance OpenBanking API v1",
    "description": "Connect a bank account, read its transactions and disconnect it. The requests are in the order you use them; run them one after the other.\n\n1. Open the collection's **Variables** tab and fill in `clientId` and `clientSecret` with the OAuth client MagniFinance issued for your integration (see https://developer.magnifinance.com/openbanking/getting-started/authentication/).\n2. Send **Get access token**. It stores the Bearer token in `accessToken`; every other request sends it automatically. Request a new one when it expires.\n3. Fill in `bankCode` and `iban` and send **Connect account**. It stores the new `accountId` and answers with `scaRedirectUrl`, where the account owner completes strong customer authentication at their bank. The account holds no data until that is done.\n4. Send **List transactions**; adjust `page`, `pageSize` and the filter variables as needed.\n5. **Disconnect account** revokes the consent and deletes the account and its transactions. It is irreversible.\n\nStaging: set `baseUrl` to `https://openbanking.office.mag.ni/api/v1` and `authUrl` to `https://auth.office.mag.ni`, with the staging credentials.\n\nUntil your OAuth client is bound to a Magni client, every call answers `403 MissingClientBinding`.\n\nDocs: https://developer.magnifinance.com/openbanking/",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{accessToken}}", "type": "string" }]
  },
  "variable": [
    { "key": "baseUrl", "value": "https://openbanking.magnifinance.com/api/v1", "description": "Production API; staging is https://openbanking.office.mag.ni/api/v1" },
    { "key": "authUrl", "value": "https://auth.magnifinance.com", "description": "Authorization server; staging is https://auth.office.mag.ni" },
    { "key": "clientId", "value": "", "description": "OAuth client id issued by MagniFinance" },
    { "key": "clientSecret", "value": "", "type": "secret", "description": "OAuth client secret issued by MagniFinance" },
    { "key": "accessToken", "value": "", "type": "secret", "description": "Filled in by Get access token; sent as the Bearer token by every other request" },
    { "key": "bankCode", "value": "", "description": "The bank's SIBS code (ASPSP)" },
    { "key": "iban", "value": "", "description": "The account IBAN; the bank is cross-checked against it" },
    { "key": "friendlyName", "value": "Main account", "description": "Optional label shown in the OpenBanking portal" },
    { "key": "accountId", "value": "", "description": "Filled in by Connect account" },
    { "key": "page", "value": "1", "description": "1-based page of transactions" },
    { "key": "pageSize", "value": "50", "description": "Transactions per page, maximum 200" }
  ],
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Every error has one shape: {\"error\": \"<Code>\", \"message\": \"<text>\"}.",
          "if ((pm.response.headers.get('Content-Type') || '').includes('json') && pm.response.text()) {",
          "    const body = pm.response.json();",
          "    pm.test('No API error', () => pm.expect(body.error, `${body.error}: ${body.message}`).to.be.undefined);",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "Get access token",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
              "const body = pm.response.json();",
              "pm.test('Bearer token issued', () => pm.expect(body.token_type, body.error_description || body.error).to.equal('Bearer'));",
              "if (body.access_token) pm.collectionVariables.set('accessToken', body.access_token);"
            ]
          }
        }
      ],
      "request": {
        "auth": { "type": "noauth" },
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/x-www-form-urlencoded" },
          { "key": "User-Agent", "value": "postman-openbanking-collection/1.0", "description": "The authorization server rejects an empty or bare curl User-Agent" }
        ],
        "url": { "raw": "{{authUrl}}/connect/token", "host": ["{{authUrl}}"], "path": ["connect", "token"] },
        "body": {
          "mode": "urlencoded",
          "urlencoded": [
            { "key": "grant_type", "value": "client_credentials" },
            { "key": "client_id", "value": "{{clientId}}" },
            { "key": "client_secret", "value": "{{clientSecret}}" },
            { "key": "scope", "value": "openbanking.api" }
          ]
        },
        "description": "OAuth 2.0 client-credentials grant with the `openbanking.api` scope. Stores `access_token` in `accessToken`. There is no refresh token: request a new one when `expires_in` runs out.\n\nDocs: https://developer.magnifinance.com/openbanking/getting-started/authentication/"
      }
    },
    {
      "name": "Connect account",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP 201 Created', () => pm.response.to.have.status(201));",
              "const body = pm.response.json();",
              "if (body.accountId) pm.collectionVariables.set('accountId', body.accountId);",
              "if (body.scaRedirectUrl) console.log('Send the account owner to complete SCA at: ' + body.scaRedirectUrl);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" }
        ],
        "url": { "raw": "{{baseUrl}}/accounts", "host": ["{{baseUrl}}"], "path": ["accounts"] },
        "body": {
          "mode": "raw",
          "options": { "raw": { "language": "json" } },
          "raw": "{\n  \"bankCode\": \"{{bankCode}}\",\n  \"iban\": \"{{iban}}\",\n  \"friendlyName\": \"{{friendlyName}}\"\n}"
        },
        "description": "Registers a bank account by IBAN for the Magni client bound to your OAuth client and starts the bank consent. IBAN accounts at SIBS-adherent banks only. Stores `accountId`; `scaRedirectUrl` is where the owner completes SCA. `400 InvalidIban` when the IBAN does not validate or its bank is not supported.\n\nDocs: https://developer.magnifinance.com/openbanking/accounts/connect-account/"
      }
    },
    {
      "name": "List transactions",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP 200', () => pm.response.to.have.status(200));",
              "const body = pm.response.json();",
              "pm.test('Paged list of transactions', () => pm.expect(body.transactions).to.be.an('array'));",
              "if (body.totalPages !== undefined) console.log(`page ${body.page} of ${body.totalPages}, ${body.totalCount} transactions`);"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{baseUrl}}/transactions?accountId={{accountId}}&page={{page}}&pageSize={{pageSize}}",
          "host": ["{{baseUrl}}"],
          "path": ["transactions"],
          "query": [
            { "key": "accountId", "value": "{{accountId}}" },
            { "key": "page", "value": "{{page}}" },
            { "key": "pageSize", "value": "{{pageSize}}" },
            { "key": "from", "value": "", "description": "Booking-date range start, ISO 8601", "disabled": true },
            { "key": "to", "value": "", "description": "Booking-date range end, ISO 8601", "disabled": true },
            { "key": "search", "value": "", "description": "Free text over the description", "disabled": true },
            { "key": "type", "value": "", "description": "Transaction type", "disabled": true },
            { "key": "status", "value": "", "description": "Transaction status", "disabled": true },
            { "key": "minAmount", "value": "", "disabled": true },
            { "key": "maxAmount", "value": "", "disabled": true }
          ]
        },
        "description": "The account's transactions from MagniFinance's synced store, filtered and paged: reading never spends the bank consent's daily allowance. Enable the optional filters in the **Params** tab. Iterate while `page < totalPages`.\n\nDocs: https://developer.magnifinance.com/openbanking/transactions/list-transactions/"
      }
    },
    {
      "name": "Disconnect account",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('HTTP 204 No Content', () => pm.response.to.have.status(204));",
              "if (pm.response.code === 204) pm.collectionVariables.set('accountId', '');"
            ]
          }
        }
      ],
      "request": {
        "method": "DELETE",
        "header": [],
        "url": { "raw": "{{baseUrl}}/accounts/{{accountId}}", "host": ["{{baseUrl}}"], "path": ["accounts", "{{accountId}}"] },
        "description": "Revokes the consent at the bank, then deletes the account and every transaction synced for it. Irreversible: reconnecting means a new **Connect account** and a new SCA by the owner. `404 NotFound` when the id does not exist or belongs to another Magni client.\n\nDocs: https://developer.magnifinance.com/openbanking/accounts/disconnect-account/"
      }
    }
  ]
}
