Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Lianja) Rabobank GET /v3/accountsDemonstrates a call to a Rabobank API. Specifically this makes a call to the "Accounts AIS sb" API to deliver all the consented payments accounts for a specific Rabobank customer. (This includes source code to for signing requests for PSD2 APIs) For more information, see https://developer-sandbox.rabobank.nl/reference/accounts-ais-sb/3-0-8
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loHttp = createobject("CkHttp") // Implements the following CURL command: // curl --request GET \ // --url https://api-sandbox.rabobank.nl/openapi/sandbox/payments/account-information/ais/v3/accounts \ // --header 'accept: application/json' \ // --header 'authorization: Bearer REPLACE_BEARER_TOKEN' \ // --header 'date: REPLACE_THIS_VALUE' \ // --header 'digest: REPLACE_THIS_VALUE' \ // --header 'psu-ip-address: OPTIONAL' \ // --header 'signature: REPLACE_THIS_VALUE' \ // --header 'tpp-signature-certificate: MIIDkDCCAnigA ... cwE6gUl0rMA==' \ // --header 'x-ibm-client-id: Client ID' \ // --header 'x-request-id: REPLACE_THIS_VALUE' // Load the previously fetched OAuth2 access token. loJsonToken = createobject("CkJsonObject") llSuccess = loJsonToken.LoadFile("qa_data/tokens/rabobank.json") if (llSuccess = .F.) then ? loJsonToken.LastErrorText release loHttp release loJsonToken return endif // This adds the "authorization: Bearer REPLACE_BEARER_TOKEN" header. loHttp.AuthToken = loJsonToken.StringOf("access_token") // This is the TTP Signature certificate: The certificate used for signing the request. loSbTppCert = createobject("CkStringBuilder") loSbTppCert.Append("MIIDkDCCAnigAwIBAgIEWs3AJDANBgkqhkiG9w0BAQsFADCBiTELMAkGA1UEBhMC") loSbTppCert.Append("TkwxEDAOBgNVBAgMB1V0cmVjaHQxEDAOBgNVBAcMB1V0cmVjaHQxETAPBgNVBAoM") loSbTppCert.Append("CFJhYm9iYW5rMRwwGgYDVQQLDBNPbmxpbmUgVHJhbnNhY3Rpb25zMSUwIwYDVQQD") loSbTppCert.Append("DBxQU0QyIEFQSSBQSSBTZXJ2aWNlcyBTYW5kYm94MB4XDTE4MDQxMTA3NTgyOFoX") loSbTppCert.Append("DTIzMDQxMTA3NTgyOFowgYkxCzAJBgNVBAYTAk5MMRAwDgYDVQQIDAdVdHJlY2h0") loSbTppCert.Append("MRAwDgYDVQQHDAdVdHJlY2h0MREwDwYDVQQKDAhSYWJvYmFuazEcMBoGA1UECwwT") loSbTppCert.Append("T25saW5lIFRyYW5zYWN0aW9uczElMCMGA1UEAwwcUFNEMiBBUEkgUEkgU2Vydmlj") loSbTppCert.Append("ZXMgU2FuZGJveDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANoAjqGW") loSbTppCert.Append("UgCIm2F+0sBSEwLal+T3u+uldLikpxHCB8iL1GD7FrRjcA+MVsxhvHly7vRsHK+t") loSbTppCert.Append("QyMSaeK782RHpY33qxPLc8LmoQLb2EuiQxXj9POYkYBQ74qkrZnvKVlR3WoyQWeD") loSbTppCert.Append("OXnSY2wbNFfkP8ET4ElwyuIIEriwYhab0OIrnnrO8X82/SPZxHwEd3aQjQ6uhiw8") loSbTppCert.Append("paDspJbS5WjEfuwY16KVVUYlhbtAwGjvc6aK0NBm+LH9fMLpAE6gfGZNy0gzMDor") loSbTppCert.Append("VNbkQK1IoAGD8p9ZHdB0F3FwkILEjUiQW6nK+/fKDNJ0TBbpgZUpY8bR460qzxKd") loSbTppCert.Append("eZ1yPDqX2Cjh6fkCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAYL4iD6noMJAt63kD") loSbTppCert.Append("ED4RB2mII/lssvHhcxuDpOm3Ims9urubFWEpvV5TgIBAxy9PBinOdjhO1kGJJnYi") loSbTppCert.Append("7F1jv1qnZwTV1JhYbvxv3+vk0jaiu7Ew7G3ASlzruXyMhN6t6jk9MpaWGl5Uw1T+") loSbTppCert.Append("gNRUcWQRR44g3ahQRIS/UHkaV+vcpOa8j186/1X0ULHfbcVQk4LMmJeXqNs8sBAU") loSbTppCert.Append("dKU/c6ssvj8jfJ4SfrurcBhY5UBTOdQOXTPY85aU3iFloerx7Oi9EHewxInOrU5X") loSbTppCert.Append("zqqTz2AQPXezexVeAQxP27lzqCmYC7CFiam6QBr06VebkmnPLfs76n8CDc1cwE6g") loSbTppCert.Append("Ul0rMA==") loHttp.SetRequestHeader("tpp-signature-certificate",loSbTppCert.GetAsString()) // ---------------------------------------------------------------- // We're not going to add the psu-ip-address header in this example. // ---------------------------------------------------------------- // X-Request-ID header... // Generate a UUID v4. loCrypt = createobject("CkCrypt2") lcXRequestId = loCrypt.GenerateUuid() loHttp.SetRequestHeader("x-request-id",lcXRequestId) // ---------------------------------------------------------------- // Date header... loDt = createobject("CkDateTime") loDt.SetFromCurrentSystemTime() lcDateHdrVal = loDt.GetAsRfc822(.F.) // The desire date/time format is the "RFC822" format. loHttp.SetRequestHeader("Date",lcDateHdrVal) // ---------------------------------------------------------------- // Digest header... loCrypt.HashAlgorithm = "SHA256" loCrypt.EncodingMode = "base64" // A GET request has no HTTP request body. Therefore the payload is the empty string. lcPayload = "" lcPayloadDigest = loCrypt.HashStringENC(lcPayload) loSbDigestHdrVal = createobject("CkStringBuilder") loSbDigestHdrVal.Append("SHA-256=") loSbDigestHdrVal.Append(lcPayloadDigest) loHttp.SetRequestHeader("digest",loSbDigestHdrVal.GetAsString()) // ---------------------------------------------------------------- // The HTTP request needs to be signed for PSD2 API's... // Create the signing string (to use in signing the HTTP request). // See https://developer.rabobank.nl/signing-requests-psd2-apis // // For "account information" HTTP requests, we must use the following headers in the signing string. // date // digest // x-request-id loSbStringToSign = createobject("CkStringBuilder") loSbStringToSign.Append("date: ") loSbStringToSign.AppendLine(lcDateHdrVal,.F.) loSbStringToSign.Append("digest: ") loSbStringToSign.AppendLine(loSbDigestHdrVal.GetAsString(),.F.) loSbStringToSign.Append("x-request-id: ") loSbStringToSign.Append(lcXRequestId) // ---------------------------------------------------------------- // Sign with our private key... loSbPrivKey = createobject("CkStringBuilder") loSbPrivKey.Append("MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDaAI6hllIAiJth") loSbPrivKey.Append("ftLAUhMC2pfk97vrpXS4pKcRwgfIi9Rg+xa0Y3APjFbMYbx5cu70bByvrUMjEmni") loSbPrivKey.Append("u/NkR6WN96sTy3PC5qEC29hLokMV4/TzmJGAUO+KpK2Z7ylZUd1qMkFngzl50mNs") loSbPrivKey.Append("GzRX5D/BE+BJcMriCBK4sGIWm9DiK556zvF/Nv0j2cR8BHd2kI0OroYsPKWg7KSW") loSbPrivKey.Append("0uVoxH7sGNeilVVGJYW7QMBo73OmitDQZvix/XzC6QBOoHxmTctIMzA6K1TW5ECt") loSbPrivKey.Append("SKABg/KfWR3QdBdxcJCCxI1IkFupyvv3ygzSdEwW6YGVKWPG0eOtKs8SnXmdcjw6") loSbPrivKey.Append("l9go4en5AgMBAAECggEAB8nsTqalwGIhFw8mbXuhNUFlGuek/arYLD6pv28swwQH") loSbPrivKey.Append("7v0ZlxFUcCHF+iBl0PsDwZTZQ4ePtgGS6ehoLkWHCzb1lEv5E1YVG5qKNE2UUwRl") loSbPrivKey.Append("fIyPakO6AzyV/UF3uzq7C+/GuXGNTKZxKewg5yD/DCFvKoCOpxu9u36FyqP/hw0S") loSbPrivKey.Append("ADVlmp35/zoPDPZzu1j4FiCo0pJ9LwJcHxeJHopNAKDw9k6I4z/grskdgupsGzK2") loSbPrivKey.Append("BiGiQ/+wmmO68/6Xa6KWfpr1PQ6ODJHgzZsdGCVi6Ebaqlj6BbsYWxP6h3lrsGt+") loSbPrivKey.Append("LmHBaN2jCD6cDp+lihqFgnm8hfdv0lmbPilp71EDfwKBgQD6U8PBzZtN8yXm5WuS") loSbPrivKey.Append("NL+/8q5GjNmeTJBSo1gM6Y8vOT4QAE147LbVuVBDwyHPoSrNejePae6Q14PswjBy") loSbPrivKey.Append("T7B8DZ0OeQyGa3trrFg/ib7Vv4ZMvJqX9+WzBrzZsxTg7oCKHzmCR4vIRItKHH3z") loSbPrivKey.Append("Wnnhqlo8ic2AZ2O43cdJosbO1wKBgQDe8UODOLu0vnHohOKeUqF3w/ZOB2+83/js") loSbPrivKey.Append("YyUbSkzsGvHIwTjObuMUFTQvdMZ6IkIyJdfnDZIbvlBSD8tzL5iKFTNCK2nL1i4G") loSbPrivKey.Append("iFr0CYLaHAlhJ5GEbTrTMDoJeBPerZq83HPrSa/Wb0xO18QTWsoVQPFfPFbbcQyI") loSbPrivKey.Append("9ryJ2iIDrwKBgQC6kuAefG46ZPVk6K2KZUJdgDUgZC52a75NuW0RAqszmUiGiJM1") loSbPrivKey.Append("g8ip9tq6BqAWrprGV0c93shusBKlzf5p1LdHXqYmeVY6gbWVhPipMrNHgN5KJ3BZ") loSbPrivKey.Append("v+w1yNnMsErpcxne2HL2hPjMJTpj3GSLkm2xIlTrNhIyl9ydlr7IRUhENQKBgQCv") loSbPrivKey.Append("i6HxbXa/90WSJTCcIcxqla8X+dsOCf3jhJ3vQy4Wq5C+1wZ35fCAG8Ifq/+so9Uj") loSbPrivKey.Append("z5CVqqXlmpF8TFuSs2OVNuRJsg14J4nOMwgLKIIUZAcurQ10DN5I9Kx+UEK1EFXL") loSbPrivKey.Append("aHsORdNjMfgQDO2jn9WHrr9gkg6CdB2+qyoCEfS+mQKBgBW08lcy9V5RzRWb/v/j") loSbPrivKey.Append("xsc7ovmgAhCJhDeV7dPbx4HbFeoQJlbA8g1thdcFlcatSGyNDbvNE1GPSd4NhkpR") loSbPrivKey.Append("Y6Hfv53kdEzjVkEtU8lUdL7HNVJqX7bU7oZlfbYcwxWQ1Gg8C1oLIAyEt71slQtd") loSbPrivKey.Append("RiNYBRZTQe2F0wxbXnuUqLAw") loPrivKey = createobject("CkPrivateKey") llSuccess = loPrivKey.LoadPem(loSbPrivKey.GetAsString()) if (llSuccess = .F.) then ? loPrivKey.LastErrorText release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey return endif loRsa = createobject("CkRsa") llSuccess = loRsa.ImportPrivateKeyObj(loPrivKey) if (llSuccess = .F.) then ? loRsa.LastErrorText release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa return endif loRsa.EncodingMode = "base64" lcB64Signature = loRsa.SignStringENC(loSbStringToSign.GetAsString(),"SHA256") // ---------------------------------------------------------------- // Add the "signature" header. // // The signature header will look like this: // signature: keyId="1523433508",algorithm="rsa-sha512",headers="date digest x-request-id",signature="y5o7gKxmfA6AT6...blE1A9Q==" // // The keyId is the serial number of the certificate as defined in 'TPP-Signing-Certificate' header, the format should be Integer not hex. loCert = createobject("CkCert") llSuccess = loCert.SetFromEncoded(loSbTppCert.GetAsString()) if (llSuccess = .F.) then ? loCert.LastErrorText release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert return endif loSbSigHdrVal = createobject("CkStringBuilder") loSbSigHdrVal.Append('keyId="') loSbSigHdrVal.Append(loCert.SerialDecimal) loSbSigHdrVal.Append('",') loSbSigHdrVal.Append('algorithm="rsa-sha256",') loSbSigHdrVal.Append('headers="date digest x-request-id",') loSbSigHdrVal.Append('signature="') loSbSigHdrVal.Append(lcB64Signature) loSbSigHdrVal.Append('"') loHttp.SetRequestHeader("signature",loSbSigHdrVal.GetAsString()) // ---------------------------------------------------------------- // Add remaining headers... loHttp.SetRequestHeader("x-ibm-client-id","YOUR_APP_CLIENT_ID") loHttp.SetRequestHeader("accept","application/json") // ---------------------------------------------------------------- // Add our certificate and key for mutual TLS // (provide a registered X509 client certificate during TLS handhake) loTlsCert = createobject("CkCert") llSuccess = loTlsCert.LoadFromFile("qa_data/certs_and_keys/ING/example_client_tls.cer") if (llSuccess = .F.) then ? loTlsCert.LastErrorText release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert release loSbSigHdrVal release loTlsCert return endif loBdPrivKey = createobject("CkBinData") llSuccess = loBdPrivKey.LoadFile("qa_data/certs_and_keys/ING/example_client_tls.key") if (llSuccess = .F.) then ? "Failed to load example_client_tls.key" release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert release loSbSigHdrVal release loTlsCert release loBdPrivKey return endif // The OAuth 2.0 client_id for these certificates is e77d776b-90af-4684-bebc-521e5b2614dd. // Please note down this client_id since you will need it in the next steps to call the API. loTlsPrivKey = createobject("CkPrivateKey") llSuccess = loTlsPrivKey.LoadAnyFormat(loBdPrivKey,"") if (llSuccess = .F.) then ? loTlsPrivKey.LastErrorText release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert release loSbSigHdrVal release loTlsCert release loBdPrivKey release loTlsPrivKey return endif // Associate the private key with the certificate. llSuccess = loTlsCert.SetPrivateKey(loTlsPrivKey) if (llSuccess = .F.) then ? loTlsCert.LastErrorText release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert release loSbSigHdrVal release loTlsCert release loBdPrivKey release loTlsPrivKey return endif llSuccess = loHttp.SetSslClientCert(loTlsCert) if (llSuccess = .F.) then ? loHttp.LastErrorText release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert release loSbSigHdrVal release loTlsCert release loBdPrivKey release loTlsPrivKey return endif // ---------------------------------------------------------------- // Finally, send the request... loSbResponseBody = createobject("CkStringBuilder") llSuccess = loHttp.QuickGetSb("https://api-sandbox.rabobank.nl/openapi/sandbox/payments/account-information/ais/v3/accounts",loSbResponseBody) if (llSuccess = .F.) then ? loHttp.LastErrorText ? loSbResponseBody.GetAsString() release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert release loSbSigHdrVal release loTlsCert release loBdPrivKey release loTlsPrivKey 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 loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert release loSbSigHdrVal release loTlsCert release loBdPrivKey release loTlsPrivKey release loSbResponseBody release loJResp return endif // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "accounts": [ // { // "_links": { // "account": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY", // "balances": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY/balances", // "transactions": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY/transactions" // }, // "currency": "EUR", // "iban": "NL05RABO0812836782", // "name": "Rosie Roy", // "resourceId": "dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY", // "status": "enabled" // } // ] // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON i = 0 lnCount_i = loJResp.SizeOfArray("accounts") do while i < lnCount_i loJResp.I = i lcV_linksAccount = loJResp.StringOf("accounts[i]._links.account") lcV_linksBalances = loJResp.StringOf("accounts[i]._links.balances") lcV_linksTransactions = loJResp.StringOf("accounts[i]._links.transactions") lcCurrency = loJResp.StringOf("accounts[i].currency") lcIban = loJResp.StringOf("accounts[i].iban") lcName = loJResp.StringOf("accounts[i].name") lcResourceId = loJResp.StringOf("accounts[i].resourceId") lcStatus = loJResp.StringOf("accounts[i].status") i = i + 1 enddo release loHttp release loJsonToken release loSbTppCert release loCrypt release loDt release loSbDigestHdrVal release loSbStringToSign release loSbPrivKey release loPrivKey release loRsa release loCert release loSbSigHdrVal release loTlsCert release loBdPrivKey release loTlsPrivKey release loSbResponseBody release loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.