Sample code for 30+ languages & platforms
Lianja 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 Lianja Downloads

Lianja
llSuccess = .F.

//  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.)
loCert = createobject("CkCert")
llSuccess = loCert.LoadPfxFile("qa_data/pfx/my_ibanity_certificate.pfx","my_pfx_password")
if (llSuccess = .F.) then
    ? loCert.LastErrorText
    release loCert
    return
endif

//  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.

loDtNow = createobject("CkDateTime")
loDtNow.SetFromCurrentSystemTime()
lcCreated = loDtNow.GetAsUnixTimeStr(.F.)

loCrypt2 = createobject("CkCrypt2")
loCrypt2.HashAlgorithm = "sha512"
loCrypt2.EncodingMode = "base64"

loSbDigestHdrValue = createobject("CkStringBuilder")
loSbDigestHdrValue.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.
loSbDigestHdrValue.Append(loCrypt2.HashStringENC(""))

? "Generated Digest"
? loSbDigestHdrValue.GetAsString()

lcRequest_target = "get /xs2a/financial-institutions"

loSbSigningString = createobject("CkStringBuilder")
loSbSigningString.Append("(request-target): ")
loSbSigningString.AppendLine(lcRequest_target,.F.)
loSbSigningString.Append("host: ")
loSbSigningString.AppendLine("api.ibanity.com",.F.)
loSbSigningString.Append("digest: ")
loSbSigningString.AppendLine(loSbDigestHdrValue.GetAsString(),.F.)
loSbSigningString.Append("(created): ")
loSbSigningString.Append(lcCreated)
//  ibanity-idempotency-key is not used with GET requests.

? "Signing String:"
? loSbSigningString.GetAsString()

lcSigned_headers_list = "(request-target) host digest (created)"

loPrivKey = createobject("CkPrivateKey")
llSuccess = loPrivKey.LoadEncryptedPemFile("my_ibanity_signature_private_key.pem","pem_password")
if (llSuccess = .F.) then
    ? loPrivKey.LastErrorText
    release loCert
    release loDtNow
    release loCrypt2
    release loSbDigestHdrValue
    release loSbSigningString
    release loPrivKey
    return
endif

loRsa = createobject("CkRsa")
loRsa.PssSaltLen = 32
loRsa.EncodingMode = "base64"
//  Use the RSASSA-PSS signature algorithm
loRsa.PkcsPadding = .F.

llSuccess = loRsa.UsePrivateKey(loPrivKey)
if (llSuccess = .F.) then
    ? loRsa.LastErrorText
    release loCert
    release loDtNow
    release loCrypt2
    release loSbDigestHdrValue
    release loSbSigningString
    release loPrivKey
    release loRsa
    return
endif

//  Sign the signing string.
lcSigBase64 = loRsa.SignStringENC(loSbSigningString.GetAsString(),"sha-256")
if (loRsa.LastMethodSuccess = .F.) then
    ? loRsa.LastErrorText
    release loCert
    release loDtNow
    release loCrypt2
    release loSbDigestHdrValue
    release loSbSigningString
    release loPrivKey
    release loRsa
    return
endif

? "Signature:"
? lcSigBase64

//  Build the signature header value.
loSbSigHeaderValue = createobject("CkStringBuilder")
loSbSigHeaderValue.Append('keyId="')
//  Use your identifier for the application's signature certificate, obtained from the Developer Portal
loSbSigHeaderValue.Append("a0ce296d-84c8-4bd5-8eb4-de0339950cfa")
loSbSigHeaderValue.Append('",created=')
loSbSigHeaderValue.Append(lcCreated)
loSbSigHeaderValue.Append(',algorithm="hs2019",headers="')
loSbSigHeaderValue.Append(lcSigned_headers_list)
loSbSigHeaderValue.Append('",signature="')
loSbSigHeaderValue.Append(lcSigBase64)
loSbSigHeaderValue.Append('"')

//  Send the GET request..
loHttp = createobject("CkHttp")

llSuccess = loHttp.SetSslClientCert(loCert)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    release loCert
    release loDtNow
    release loCrypt2
    release loSbDigestHdrValue
    release loSbSigningString
    release loPrivKey
    release loRsa
    release loSbSigHeaderValue
    release loHttp
    return
endif

loHttp.SetRequestHeader("Signature",loSbSigHeaderValue.GetAsString())
loHttp.SetRequestHeader("Digest",loSbDigestHdrValue.GetAsString())

loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb("https://api.ibanity.com/xs2a/financial-institutions",loSbResponseBody)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    release loCert
    release loDtNow
    release loCrypt2
    release loSbDigestHdrValue
    release loSbSigningString
    release loPrivKey
    release loRsa
    release loSbSigHeaderValue
    release loHttp
    release loSbResponseBody
    return
endif

loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    release loCert
    release loDtNow
    release loCrypt2
    release loSbDigestHdrValue
    release loSbSigningString
    release loPrivKey
    release loRsa
    release loSbSigHeaderValue
    release loHttp
    release loSbResponseBody
    release loJResp
    return
endif

//  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

lcLinksFirst = loJResp.StringOf("links.first")
lnMetaPagingLimit = loJResp.IntOf("meta.paging.limit")
i = 0
lnCount_i = loJResp.SizeOfArray("data")
do while i < lnCount_i
    loJResp.I = i
    lcAttributesBic = loJResp.StringOf("data[i].attributes.bic")
    llAttributesBulkPaymentsEnabled = loJResp.BoolOf("data[i].attributes.bulkPaymentsEnabled")
    lcAttributesCountry = loJResp.StringOf("data[i].attributes.country")
    llAttributesFinancialInstitutionCustomerReferenceRequired = loJResp.BoolOf("data[i].attributes.financialInstitutionCustomerReferenceRequired")
    llAttributesFutureDatedPaymentsAllowed = loJResp.BoolOf("data[i].attributes.futureDatedPaymentsAllowed")
    lcAttributesLogoUrl = loJResp.StringOf("data[i].attributes.logoUrl")
    lcAttributesMaintenanceFrom = loJResp.StringOf("data[i].attributes.maintenanceFrom")
    lcAttributesMaintenanceTo = loJResp.StringOf("data[i].attributes.maintenanceTo")
    lcAttributesMaintenanceType = loJResp.StringOf("data[i].attributes.maintenanceType")
    lcAttributesMaxRequestedAccountReferences = loJResp.StringOf("data[i].attributes.maxRequestedAccountReferences")
    lnAttributesMinRequestedAccountReferences = loJResp.IntOf("data[i].attributes.minRequestedAccountReferences")
    lcAttributesName = loJResp.StringOf("data[i].attributes.name")
    llAttributesPaymentsEnabled = loJResp.BoolOf("data[i].attributes.paymentsEnabled")
    llAttributesPeriodicPaymentsEnabled = loJResp.BoolOf("data[i].attributes.periodicPaymentsEnabled")
    lcAttributesPrimaryColor = loJResp.StringOf("data[i].attributes.primaryColor")
    llAttributesRequiresCredentialStorage = loJResp.BoolOf("data[i].attributes.requiresCredentialStorage")
    llAttributesRequiresCustomerIpAddress = loJResp.BoolOf("data[i].attributes.requiresCustomerIpAddress")
    llAttributesSandbox = loJResp.BoolOf("data[i].attributes.sandbox")
    lcAttributesSecondaryColor = loJResp.StringOf("data[i].attributes.secondaryColor")
    lcAttributesSharedBrandName = loJResp.StringOf("data[i].attributes.sharedBrandName")
    lcAttributesSharedBrandReference = loJResp.StringOf("data[i].attributes.sharedBrandReference")
    lcAttributesStatus = loJResp.StringOf("data[i].attributes.status")
    lcId = loJResp.StringOf("data[i].id")
    lcLinksSelf = loJResp.StringOf("data[i].links.self")
    lcV_type = loJResp.StringOf("data[i].type")
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.authorizationModels")
    do while j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.authorizationModels[j]")
        j = j + 1
    enddo
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.bulkPaymentsProductTypes")
    do while j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.bulkPaymentsProductTypes[j]")
        j = j + 1
    enddo
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.paymentsProductTypes")
    do while j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.paymentsProductTypes[j]")
        j = j + 1
    enddo
    j = 0
    lnCount_j = loJResp.SizeOfArray("data[i].attributes.periodicPaymentsProductTypes")
    do while j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("data[i].attributes.periodicPaymentsProductTypes[j]")
        j = j + 1
    enddo
    i = i + 1
enddo


release loCert
release loDtNow
release loCrypt2
release loSbDigestHdrValue
release loSbSigningString
release loPrivKey
release loRsa
release loSbSigHeaderValue
release loHttp
release loSbResponseBody
release loJResp