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

Xbase++
LOCAL nSuccess
LOCAL oCert
LOCAL oDtNow
LOCAL cCreated
LOCAL oCrypt2
LOCAL oSbDigestHdrValue
LOCAL cRequest_target
LOCAL oSbSigningString
LOCAL cSigned_headers_list
LOCAL oPrivKey
LOCAL oRsa
LOCAL cSigBase64
LOCAL oSbSigHeaderValue
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cAttributesBic
LOCAL nAttributesBulkPaymentsEnabled
LOCAL cAttributesCountry
LOCAL nAttributesFinancialInstitutionCustomerReferenceRequired
LOCAL nAttributesFutureDatedPaymentsAllowed
LOCAL cAttributesLogoUrl
LOCAL cAttributesMaintenanceFrom
LOCAL cAttributesMaintenanceTo
LOCAL cAttributesMaintenanceType
LOCAL cAttributesMaxRequestedAccountReferences
LOCAL nAttributesMinRequestedAccountReferences
LOCAL cAttributesName
LOCAL nAttributesPaymentsEnabled
LOCAL nAttributesPeriodicPaymentsEnabled
LOCAL cAttributesPrimaryColor
LOCAL nAttributesRequiresCredentialStorage
LOCAL nAttributesRequiresCustomerIpAddress
LOCAL nAttributesSandbox
LOCAL cAttributesSecondaryColor
LOCAL cAttributesSharedBrandName
LOCAL cAttributesSharedBrandReference
LOCAL cAttributesStatus
LOCAL cId
LOCAL cLinksSelf
LOCAL cV_type
LOCAL j
LOCAL nCount_j
LOCAL cStrVal
LOCAL cLinksFirst
LOCAL nMetaPagingLimit
LOCAL i
LOCAL nCount_i

nSuccess := 0

//  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.)
oCert := CreateObject("Chilkat.Cert")
nSuccess := oCert:LoadPfxFile("qa_data/pfx/my_ibanity_certificate.pfx", "my_pfx_password")
IF (nSuccess == 0)
    ? oCert:LastErrorText
    oCert:destroy()
    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.

oDtNow := CreateObject("Chilkat.CkDateTime")
oDtNow:SetFromCurrentSystemTime()
cCreated := oDtNow:GetAsUnixTimeStr(0)

oCrypt2 := CreateObject("Chilkat.Crypt2")
oCrypt2:HashAlgorithm := "sha512"
oCrypt2:EncodingMode := "base64"

oSbDigestHdrValue := CreateObject("Chilkat.StringBuilder")
oSbDigestHdrValue: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.
oSbDigestHdrValue:Append(oCrypt2:HashStringENC(""))

? "Generated Digest"
? oSbDigestHdrValue:GetAsString()

cRequest_target := "get /xs2a/financial-institutions"

oSbSigningString := CreateObject("Chilkat.StringBuilder")
oSbSigningString:Append("(request-target): ")
oSbSigningString:AppendLine(cRequest_target, 0)
oSbSigningString:Append("host: ")
oSbSigningString:AppendLine("api.ibanity.com", 0)
oSbSigningString:Append("digest: ")
oSbSigningString:AppendLine(oSbDigestHdrValue:GetAsString(), 0)
oSbSigningString:Append("(created): ")
oSbSigningString:Append(cCreated)
//  ibanity-idempotency-key is not used with GET requests.

? "Signing String:"
? oSbSigningString:GetAsString()

cSigned_headers_list := "(request-target) host digest (created)"

oPrivKey := CreateObject("Chilkat.PrivateKey")
nSuccess := oPrivKey:LoadEncryptedPemFile("my_ibanity_signature_private_key.pem", "pem_password")
IF (nSuccess == 0)
    ? oPrivKey:LastErrorText
    oCert:destroy()
    oDtNow:destroy()
    oCrypt2:destroy()
    oSbDigestHdrValue:destroy()
    oSbSigningString:destroy()
    oPrivKey:destroy()
    RETURN
ENDIF

oRsa := CreateObject("Chilkat.Rsa")
oRsa:PssSaltLen := 32
oRsa:EncodingMode := "base64"
//  Use the RSASSA-PSS signature algorithm
oRsa:PkcsPadding := 0

nSuccess := oRsa:UsePrivateKey(oPrivKey)
IF (nSuccess == 0)
    ? oRsa:LastErrorText
    oCert:destroy()
    oDtNow:destroy()
    oCrypt2:destroy()
    oSbDigestHdrValue:destroy()
    oSbSigningString:destroy()
    oPrivKey:destroy()
    oRsa:destroy()
    RETURN
ENDIF

//  Sign the signing string.
cSigBase64 := oRsa:SignStringENC(oSbSigningString:GetAsString(), "sha-256")
IF (oRsa:LastMethodSuccess == 0)
    ? oRsa:LastErrorText
    oCert:destroy()
    oDtNow:destroy()
    oCrypt2:destroy()
    oSbDigestHdrValue:destroy()
    oSbSigningString:destroy()
    oPrivKey:destroy()
    oRsa:destroy()
    RETURN
ENDIF

? "Signature:"
? cSigBase64

//  Build the signature header value.
oSbSigHeaderValue := CreateObject("Chilkat.StringBuilder")
oSbSigHeaderValue:Append('keyId="')
//  Use your identifier for the application's signature certificate, obtained from the Developer Portal
oSbSigHeaderValue:Append("a0ce296d-84c8-4bd5-8eb4-de0339950cfa")
oSbSigHeaderValue:Append('",created=')
oSbSigHeaderValue:Append(cCreated)
oSbSigHeaderValue:Append(',algorithm="hs2019",headers="')
oSbSigHeaderValue:Append(cSigned_headers_list)
oSbSigHeaderValue:Append('",signature="')
oSbSigHeaderValue:Append(cSigBase64)
oSbSigHeaderValue:Append('"')

//  Send the GET request..
oHttp := CreateObject("Chilkat.Http")

nSuccess := oHttp:SetSslClientCert(oCert)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oCert:destroy()
    oDtNow:destroy()
    oCrypt2:destroy()
    oSbDigestHdrValue:destroy()
    oSbSigningString:destroy()
    oPrivKey:destroy()
    oRsa:destroy()
    oSbSigHeaderValue:destroy()
    oHttp:destroy()
    RETURN
ENDIF

oHttp:SetRequestHeader("Signature", oSbSigHeaderValue:GetAsString())
oHttp:SetRequestHeader("Digest", oSbDigestHdrValue:GetAsString())

oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://api.ibanity.com/xs2a/financial-institutions", oSbResponseBody)
IF (nSuccess == 0)
    ? oHttp:LastErrorText
    oCert:destroy()
    oDtNow:destroy()
    oCrypt2:destroy()
    oSbDigestHdrValue:destroy()
    oSbSigningString:destroy()
    oPrivKey:destroy()
    oRsa:destroy()
    oSbSigHeaderValue:destroy()
    oHttp:destroy()
    oSbResponseBody:destroy()
    RETURN
ENDIF

oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0

? "Response Body:"
? oJResp:Emit()

nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
    ? "Response Header:"
    ? oHttp:LastHeader
    ? "Failed."
    oCert:destroy()
    oDtNow:destroy()
    oCrypt2:destroy()
    oSbDigestHdrValue:destroy()
    oSbSigningString:destroy()
    oPrivKey:destroy()
    oRsa:destroy()
    oSbSigHeaderValue:destroy()
    oHttp:destroy()
    oSbResponseBody:destroy()
    oJResp:destroy()
    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

cLinksFirst := oJResp:StringOf("links.first")
nMetaPagingLimit := oJResp:IntOf("meta.paging.limit")
i := 0
nCount_i := oJResp:SizeOfArray("data")
DO WHILE i < nCount_i
    oJResp:I := i
    cAttributesBic := oJResp:StringOf("data[i].attributes.bic")
    nAttributesBulkPaymentsEnabled := oJResp:BoolOf("data[i].attributes.bulkPaymentsEnabled")
    cAttributesCountry := oJResp:StringOf("data[i].attributes.country")
    nAttributesFinancialInstitutionCustomerReferenceRequired := oJResp:BoolOf("data[i].attributes.financialInstitutionCustomerReferenceRequired")
    nAttributesFutureDatedPaymentsAllowed := oJResp:BoolOf("data[i].attributes.futureDatedPaymentsAllowed")
    cAttributesLogoUrl := oJResp:StringOf("data[i].attributes.logoUrl")
    cAttributesMaintenanceFrom := oJResp:StringOf("data[i].attributes.maintenanceFrom")
    cAttributesMaintenanceTo := oJResp:StringOf("data[i].attributes.maintenanceTo")
    cAttributesMaintenanceType := oJResp:StringOf("data[i].attributes.maintenanceType")
    cAttributesMaxRequestedAccountReferences := oJResp:StringOf("data[i].attributes.maxRequestedAccountReferences")
    nAttributesMinRequestedAccountReferences := oJResp:IntOf("data[i].attributes.minRequestedAccountReferences")
    cAttributesName := oJResp:StringOf("data[i].attributes.name")
    nAttributesPaymentsEnabled := oJResp:BoolOf("data[i].attributes.paymentsEnabled")
    nAttributesPeriodicPaymentsEnabled := oJResp:BoolOf("data[i].attributes.periodicPaymentsEnabled")
    cAttributesPrimaryColor := oJResp:StringOf("data[i].attributes.primaryColor")
    nAttributesRequiresCredentialStorage := oJResp:BoolOf("data[i].attributes.requiresCredentialStorage")
    nAttributesRequiresCustomerIpAddress := oJResp:BoolOf("data[i].attributes.requiresCustomerIpAddress")
    nAttributesSandbox := oJResp:BoolOf("data[i].attributes.sandbox")
    cAttributesSecondaryColor := oJResp:StringOf("data[i].attributes.secondaryColor")
    cAttributesSharedBrandName := oJResp:StringOf("data[i].attributes.sharedBrandName")
    cAttributesSharedBrandReference := oJResp:StringOf("data[i].attributes.sharedBrandReference")
    cAttributesStatus := oJResp:StringOf("data[i].attributes.status")
    cId := oJResp:StringOf("data[i].id")
    cLinksSelf := oJResp:StringOf("data[i].links.self")
    cV_type := oJResp:StringOf("data[i].type")
    j := 0
    nCount_j := oJResp:SizeOfArray("data[i].attributes.authorizationModels")
    DO WHILE j < nCount_j
        oJResp:J := j
        cStrVal := oJResp:StringOf("data[i].attributes.authorizationModels[j]")
        j := j + 1
    ENDDO
    j := 0
    nCount_j := oJResp:SizeOfArray("data[i].attributes.bulkPaymentsProductTypes")
    DO WHILE j < nCount_j
        oJResp:J := j
        cStrVal := oJResp:StringOf("data[i].attributes.bulkPaymentsProductTypes[j]")
        j := j + 1
    ENDDO
    j := 0
    nCount_j := oJResp:SizeOfArray("data[i].attributes.paymentsProductTypes")
    DO WHILE j < nCount_j
        oJResp:J := j
        cStrVal := oJResp:StringOf("data[i].attributes.paymentsProductTypes[j]")
        j := j + 1
    ENDDO
    j := 0
    nCount_j := oJResp:SizeOfArray("data[i].attributes.periodicPaymentsProductTypes")
    DO WHILE j < nCount_j
        oJResp:J := j
        cStrVal := oJResp:StringOf("data[i].attributes.periodicPaymentsProductTypes[j]")
        j := j + 1
    ENDDO
    i := i + 1
ENDDO

oCert:destroy()
oDtNow:destroy()
oCrypt2:destroy()
oSbDigestHdrValue:destroy()
oSbSigningString:destroy()
oPrivKey:destroy()
oRsa:destroy()
oSbSigHeaderValue:destroy()
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()