Sample code for 30+ languages & platforms
React Native Requires Chilkat v11.0.0+

Ibanity XS2A List Financial Institutions

See more Ibanity Examples

Demonstrates how to send a request to get a list of financial institutions.

Chilkat React Native Downloads

React Native
import { Cert, CkDateTime, Crypt2, Http, JsonObject, PrivateKey, Rsa, StringBuilder } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  //  Send the following request:

  // $ curl -X GET https://api.ibanity.com/xs2a/financial-institutions \
  // --cert certificate.pem \
  // --key private_key.pem \
  // -H 'Signature: keyId="75b5d796-de5c-400a-81ce-e72371b01cbc",created=1599659223,algorithm="hs2019",headers="(request-target) digest (created) host",signature="BASE64(RSA-SHA256(SIGNING_STRING))"' \
  // -H 'Digest: SHA-512=beDaRguyEb8fhh5wnl37bOTDtvhuYZyZNkTZ9LiC9Wc='

  // Ibanity provides the certificate + private key in PFX format.  This example will use the .pfx instead of the pair of PEM files.
  // (It is also possible to implement using Chilkat with the PEM files, but PFX is easier.)
  const cert = new Cert();
  try {
    cert.loadPfxFile('qa_data/pfx/my_ibanity_certificate.pfx', 'my_pfx_password');
  } catch {
    console.log(cert.lastErrorText);
    return;
  }

  // We need to calculate the Digest and Signature header fields.
  // For a detailed explanation, see Calculate Ibanity HTTP Signature Example

  // We'll just write the code here as briefly as possible.

  const dtNow = new CkDateTime();
  dtNow.setFromCurrentSystemTime();
  const created = dtNow.getAsUnixTimeStr(false);

  const crypt2 = new Crypt2();
  crypt2.hashAlgorithm = 'sha512';
  crypt2.encodingMode = 'base64';

  const sbDigestHdrValue = new StringBuilder();
  sbDigestHdrValue.append('SHA-512=');
  // GET requests have empty payloads.  The SHA-512 hash of the empty string is the same for all GET requests.
  // Therefore all GET requests will use "z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg=="
  // You can eliminate the explicit hash computation (for GET requests) and simply use the above literal string.
  sbDigestHdrValue.append(crypt2.hashStringENC(''));

  console.log('Generated Digest');
  console.log(sbDigestHdrValue.getAsString());

  const requestTarget = 'get /xs2a/financial-institutions';

  const sbSigningString = new StringBuilder();
  sbSigningString.append('(request-target): ');
  sbSigningString.appendLine(requestTarget, false);
  sbSigningString.append('host: ');
  sbSigningString.appendLine('api.ibanity.com', false);
  sbSigningString.append('digest: ');
  sbSigningString.appendLine(sbDigestHdrValue.getAsString(), false);
  sbSigningString.append('(created): ');
  sbSigningString.append(created);
  // ibanity-idempotency-key is not used with GET requests.

  console.log('Signing String:');
  console.log(sbSigningString.getAsString());

  const signedHeadersList = '(request-target) host digest (created)';

  const privKey = new PrivateKey();
  try {
    privKey.loadEncryptedPemFile('my_ibanity_signature_private_key.pem', 'pem_password');
  } catch {
    console.log(privKey.lastErrorText);
    return;
  }

  const rsa = new Rsa();
  rsa.pssSaltLen = 32;
  rsa.encodingMode = 'base64';
  // Use the RSASSA-PSS signature algorithm
  rsa.pkcsPadding = false;

  try {
    rsa.usePrivateKey(privKey);
  } catch {
    console.log(rsa.lastErrorText);
    return;
  }

  // Sign the signing string.
  let sigBase64: string;
  try {
    sigBase64 = rsa.signStringENC(sbSigningString.getAsString(), 'sha-256');
  } catch {
    console.log(rsa.lastErrorText);
    return;
  }

  console.log('Signature:');
  console.log(sigBase64);

  // Build the signature header value.
  const sbSigHeaderValue = new StringBuilder();
  sbSigHeaderValue.append('keyId="');
  // Use your identifier for the application's signature certificate, obtained from the Developer Portal
  sbSigHeaderValue.append('a0ce296d-84c8-4bd5-8eb4-de0339950cfa');
  sbSigHeaderValue.append('",created=');
  sbSigHeaderValue.append(created);
  sbSigHeaderValue.append(',algorithm="hs2019",headers="');
  sbSigHeaderValue.append(signedHeadersList);
  sbSigHeaderValue.append('",signature="');
  sbSigHeaderValue.append(sigBase64);
  sbSigHeaderValue.append('"');

  // Send the GET request..
  const http = new Http();

  try {
    http.setSslClientCert(cert);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  http.setRequestHeader('Signature', sbSigHeaderValue.getAsString());
  http.setRequestHeader('Digest', sbDigestHdrValue.getAsString());

  const sbResponseBody = new StringBuilder();
  try {
    await http.quickGetSbAsync('https://api.ibanity.com/xs2a/financial-institutions', sbResponseBody);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const jResp = new JsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  console.log('Response Body:');
  console.log(jResp.emit());

  const respStatusCode = http.lastStatus;
  console.log(`Response Status Code = ${respStatusCode}`);
  if (respStatusCode >= 400) {
    console.log('Response Header:');
    console.log(http.lastHeader);
    console.log('Failed.');
    return;
  }

  // Sample output:
  // (Sample code for parsing the JSON response is shown below)

  // {
  //   "data": [
  //     {
  //       "attributes": {
  //         "authorizationModels": [
  //           "detailed",
  //           "financialInstitutionOffered"
  //         ],
  //         "bic": "NBBEBEBB203",
  //         "bulkPaymentsEnabled": true,
  //         "bulkPaymentsProductTypes": [
  //           "sepaCreditTransfer"
  //         ],
  //         "country": null,
  //         "financialInstitutionCustomerReferenceRequired": false,
  //         "futureDatedPaymentsAllowed": true,
  //         "logoUrl": "https://s3.eu-central-1.amazonaws.com/ibanity-production-financial-institution-assets/sandbox.png",
  //         "maintenanceFrom": null,
  //         "maintenanceTo": null,
  //         "maintenanceType": null,
  //         "maxRequestedAccountReferences": null,
  //         "minRequestedAccountReferences": 0,
  //         "name": "Bogus Financial",
  //         "paymentsEnabled": true,
  //         "paymentsProductTypes": [
  //           "sepaCreditTransfer"
  //         ],
  //         "periodicPaymentsEnabled": true,
  //         "periodicPaymentsProductTypes": [
  //           "sepaCreditTransfer"
  //         ],
  //         "primaryColor": "#7d39ff",
  //         "requiresCredentialStorage": false,
  //         "requiresCustomerIpAddress": false,
  //         "sandbox": true,
  //         "secondaryColor": "#3DF2C2",
  //         "sharedBrandName": null,
  //         "sharedBrandReference": null,
  //         "status": "beta"
  //       },
  //       "id": "2d3d70a4-cb3c-477c-97e1-cbe495b82841",
  //       "links": {
  //         "self": "https://api.ibanity.com/xs2a/financial-institutions/2d3d70a4-cb3c-477c-97e1-cbe495b82841"
  //       },
  //       "type": "financialInstitution"
  //     },
  //     {
  //       "attributes": {
  //         "authorizationModels": [
  //           "detailed",
  //           "financialInstitutionOffered"
  //         ],
  //         "bic": "NBBEBEBB203",
  //         "bulkPaymentsEnabled": true,
  //         "bulkPaymentsProductTypes": [
  //           "sepaCreditTransfer"
  //         ],
  //         "country": null,
  //         "financialInstitutionCustomerReferenceRequired": false,
  //         "futureDatedPaymentsAllowed": true,
  //         "logoUrl": "https://s3.eu-central-1.amazonaws.com/ibanity-production-financial-institution-assets/sandbox.png",
  //         "maintenanceFrom": null,
  //         "maintenanceTo": null,
  //         "maintenanceType": null,
  //         "maxRequestedAccountReferences": null,
  //         "minRequestedAccountReferences": 0,
  //         "name": "XYZ Trust",
  //         "paymentsEnabled": true,
  //         "paymentsProductTypes": [
  //           "sepaCreditTransfer"
  //         ],
  //         "periodicPaymentsEnabled": true,
  //         "periodicPaymentsProductTypes": [
  //           "sepaCreditTransfer"
  //         ],
  //         "primaryColor": "#7d39ff",
  //         "requiresCredentialStorage": false,
  //         "requiresCustomerIpAddress": false,
  //         "sandbox": true,
  //         "secondaryColor": "#3DF2C2",
  //         "sharedBrandName": null,
  //         "sharedBrandReference": null,
  //         "status": "beta"
  //       },
  //       "id": "d4100f28-936b-4379-a3f8-86314a2014fb",
  //       "links": {
  //         "self": "https://api.ibanity.com/xs2a/financial-institutions/d4100f28-936b-4379-a3f8-86314a2014fb"
  //       },
  //       "type": "financialInstitution"
  //     }
  //   ],
  //   "links": {
  //     "first": "https://api.ibanity.com/xs2a/financial-institutions"
  //   },
  //   "meta": {
  //     "paging": {
  //       "limit": 10
  //     }
  //   }
  // }

  // Sample code for parsing the JSON response...
  // Use the following online tool to generate parsing code from sample JSON:
  // Generate Parsing Code from JSON

  let attributesBic = '';
  let attributesCountry = '';
  let attributesLogoUrl = '';
  let attributesMaintenanceFrom = '';
  let attributesMaintenanceTo = '';
  let attributesMaintenanceType = '';
  let attributesMaxRequestedAccountReferences = '';
  let attributesMinRequestedAccountReferences = 0;
  let attributesName = '';
  let attributesPrimaryColor = '';
  let attributesSecondaryColor = '';
  let attributesSharedBrandName = '';
  let attributesSharedBrandReference = '';
  let attributesStatus = '';
  let id = '';
  let linksSelf = '';
  let vType = '';
  let j = 0;
  let countJ = 0;
  let strVal = '';

  const linksFirst = jResp.stringOf('links.first');
  const metaPagingLimit = jResp.intOf('meta.paging.limit');
  let i = 0;
  const countI = jResp.sizeOfArray('data');
  while (i < countI) {
    jResp.i = i;
    attributesBic = jResp.stringOf('data[i].attributes.bic');
    jResp.boolOf('data[i].attributes.bulkPaymentsEnabled');
    attributesCountry = jResp.stringOf('data[i].attributes.country');
    jResp.boolOf('data[i].attributes.financialInstitutionCustomerReferenceRequired');
    jResp.boolOf('data[i].attributes.futureDatedPaymentsAllowed');
    attributesLogoUrl = jResp.stringOf('data[i].attributes.logoUrl');
    attributesMaintenanceFrom = jResp.stringOf('data[i].attributes.maintenanceFrom');
    attributesMaintenanceTo = jResp.stringOf('data[i].attributes.maintenanceTo');
    attributesMaintenanceType = jResp.stringOf('data[i].attributes.maintenanceType');
    attributesMaxRequestedAccountReferences = jResp.stringOf('data[i].attributes.maxRequestedAccountReferences');
    attributesMinRequestedAccountReferences = jResp.intOf('data[i].attributes.minRequestedAccountReferences');
    attributesName = jResp.stringOf('data[i].attributes.name');
    jResp.boolOf('data[i].attributes.paymentsEnabled');
    jResp.boolOf('data[i].attributes.periodicPaymentsEnabled');
    attributesPrimaryColor = jResp.stringOf('data[i].attributes.primaryColor');
    jResp.boolOf('data[i].attributes.requiresCredentialStorage');
    jResp.boolOf('data[i].attributes.requiresCustomerIpAddress');
    jResp.boolOf('data[i].attributes.sandbox');
    attributesSecondaryColor = jResp.stringOf('data[i].attributes.secondaryColor');
    attributesSharedBrandName = jResp.stringOf('data[i].attributes.sharedBrandName');
    attributesSharedBrandReference = jResp.stringOf('data[i].attributes.sharedBrandReference');
    attributesStatus = jResp.stringOf('data[i].attributes.status');
    id = jResp.stringOf('data[i].id');
    linksSelf = jResp.stringOf('data[i].links.self');
    vType = jResp.stringOf('data[i].type');
    j = 0;
    countJ = jResp.sizeOfArray('data[i].attributes.authorizationModels');
    while (j < countJ) {
      jResp.j = j;
      strVal = jResp.stringOf('data[i].attributes.authorizationModels[j]');
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('data[i].attributes.bulkPaymentsProductTypes');
    while (j < countJ) {
      jResp.j = j;
      strVal = jResp.stringOf('data[i].attributes.bulkPaymentsProductTypes[j]');
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('data[i].attributes.paymentsProductTypes');
    while (j < countJ) {
      jResp.j = j;
      strVal = jResp.stringOf('data[i].attributes.paymentsProductTypes[j]');
      j++;
    }

    j = 0;
    countJ = jResp.sizeOfArray('data[i].attributes.periodicPaymentsProductTypes');
    while (j < countJ) {
      jResp.j = j;
      strVal = jResp.stringOf('data[i].attributes.periodicPaymentsProductTypes[j]');
      j++;
    }

    i++;
  }
}