Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Unicode C Web API Examples

Primary Categories

ABN AMRO
AWS Translate
Activix CRM
Adyen
Amazon DynamoDB
Amazon MWS
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bitfinex v2 REST
Bluzone
CallRail
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Jira
Lightspeed

MYOB
Magento
MercadoLibre
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
Rabobank
SOAP finkok.com
Shippo
Shopify
SimpleTexting
Square
Stripe
SugarCRM
Trello
Twilio
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
WhatsApp
WiX
WooCommerce
Xero
Yousign
_Miscellaneous_
eBay
effectconnect

 

 

 

(Unicode C) Rabobank GET /v3/accounts

Demonstrates 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

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkCrypt2W.h>
#include <C_CkDateTimeW.h>
#include <C_CkPrivateKeyW.h>
#include <C_CkRsaW.h>
#include <C_CkCertW.h>
#include <C_CkBinDataW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW jsonToken;
    HCkStringBuilderW sbTppCert;
    HCkCrypt2W crypt;
    const wchar_t *xRequestId;
    HCkDateTimeW dt;
    const wchar_t *dateHdrVal;
    const wchar_t *payload;
    const wchar_t *payloadDigest;
    HCkStringBuilderW sbDigestHdrVal;
    HCkStringBuilderW sbStringToSign;
    HCkStringBuilderW sbPrivKey;
    HCkPrivateKeyW privKey;
    HCkRsaW rsa;
    const wchar_t *b64Signature;
    HCkCertW cert;
    HCkStringBuilderW sbSigHdrVal;
    HCkCertW tlsCert;
    HCkBinDataW bdPrivKey;
    HCkPrivateKeyW tlsPrivKey;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *v_linksAccount;
    const wchar_t *v_linksBalances;
    const wchar_t *v_linksTransactions;
    const wchar_t *currency;
    const wchar_t *iban;
    const wchar_t *name;
    const wchar_t *resourceId;
    const wchar_t *status;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // 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.
    jsonToken = CkJsonObjectW_Create();
    success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/rabobank.json");
    if (success == FALSE) {
        wprintf(L"%s\n",CkJsonObjectW_lastErrorText(jsonToken));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        return;
    }

    // This adds the "authorization: Bearer REPLACE_BEARER_TOKEN" header.
    CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token"));

    // This is the TTP Signature certificate: The certificate used for signing the request.
    sbTppCert = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbTppCert,L"MIIDkDCCAnigAwIBAgIEWs3AJDANBgkqhkiG9w0BAQsFADCBiTELMAkGA1UEBhMC");
    CkStringBuilderW_Append(sbTppCert,L"TkwxEDAOBgNVBAgMB1V0cmVjaHQxEDAOBgNVBAcMB1V0cmVjaHQxETAPBgNVBAoM");
    CkStringBuilderW_Append(sbTppCert,L"CFJhYm9iYW5rMRwwGgYDVQQLDBNPbmxpbmUgVHJhbnNhY3Rpb25zMSUwIwYDVQQD");
    CkStringBuilderW_Append(sbTppCert,L"DBxQU0QyIEFQSSBQSSBTZXJ2aWNlcyBTYW5kYm94MB4XDTE4MDQxMTA3NTgyOFoX");
    CkStringBuilderW_Append(sbTppCert,L"DTIzMDQxMTA3NTgyOFowgYkxCzAJBgNVBAYTAk5MMRAwDgYDVQQIDAdVdHJlY2h0");
    CkStringBuilderW_Append(sbTppCert,L"MRAwDgYDVQQHDAdVdHJlY2h0MREwDwYDVQQKDAhSYWJvYmFuazEcMBoGA1UECwwT");
    CkStringBuilderW_Append(sbTppCert,L"T25saW5lIFRyYW5zYWN0aW9uczElMCMGA1UEAwwcUFNEMiBBUEkgUEkgU2Vydmlj");
    CkStringBuilderW_Append(sbTppCert,L"ZXMgU2FuZGJveDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANoAjqGW");
    CkStringBuilderW_Append(sbTppCert,L"UgCIm2F+0sBSEwLal+T3u+uldLikpxHCB8iL1GD7FrRjcA+MVsxhvHly7vRsHK+t");
    CkStringBuilderW_Append(sbTppCert,L"QyMSaeK782RHpY33qxPLc8LmoQLb2EuiQxXj9POYkYBQ74qkrZnvKVlR3WoyQWeD");
    CkStringBuilderW_Append(sbTppCert,L"OXnSY2wbNFfkP8ET4ElwyuIIEriwYhab0OIrnnrO8X82/SPZxHwEd3aQjQ6uhiw8");
    CkStringBuilderW_Append(sbTppCert,L"paDspJbS5WjEfuwY16KVVUYlhbtAwGjvc6aK0NBm+LH9fMLpAE6gfGZNy0gzMDor");
    CkStringBuilderW_Append(sbTppCert,L"VNbkQK1IoAGD8p9ZHdB0F3FwkILEjUiQW6nK+/fKDNJ0TBbpgZUpY8bR460qzxKd");
    CkStringBuilderW_Append(sbTppCert,L"eZ1yPDqX2Cjh6fkCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAYL4iD6noMJAt63kD");
    CkStringBuilderW_Append(sbTppCert,L"ED4RB2mII/lssvHhcxuDpOm3Ims9urubFWEpvV5TgIBAxy9PBinOdjhO1kGJJnYi");
    CkStringBuilderW_Append(sbTppCert,L"7F1jv1qnZwTV1JhYbvxv3+vk0jaiu7Ew7G3ASlzruXyMhN6t6jk9MpaWGl5Uw1T+");
    CkStringBuilderW_Append(sbTppCert,L"gNRUcWQRR44g3ahQRIS/UHkaV+vcpOa8j186/1X0ULHfbcVQk4LMmJeXqNs8sBAU");
    CkStringBuilderW_Append(sbTppCert,L"dKU/c6ssvj8jfJ4SfrurcBhY5UBTOdQOXTPY85aU3iFloerx7Oi9EHewxInOrU5X");
    CkStringBuilderW_Append(sbTppCert,L"zqqTz2AQPXezexVeAQxP27lzqCmYC7CFiam6QBr06VebkmnPLfs76n8CDc1cwE6g");
    CkStringBuilderW_Append(sbTppCert,L"Ul0rMA==");
    CkHttpW_SetRequestHeader(http,L"tpp-signature-certificate",CkStringBuilderW_getAsString(sbTppCert));

    // ----------------------------------------------------------------
    // We're not going to add the psu-ip-address header in this example.

    // ----------------------------------------------------------------
    // X-Request-ID header...
    // Generate a UUID v4.
    crypt = CkCrypt2W_Create();
    xRequestId = CkCrypt2W_generateUuid(crypt);
    CkHttpW_SetRequestHeader(http,L"x-request-id",xRequestId);

    // ----------------------------------------------------------------
    // Date header...
    dt = CkDateTimeW_Create();
    CkDateTimeW_SetFromCurrentSystemTime(dt);
    dateHdrVal = CkDateTimeW_getAsRfc822(dt,FALSE);
    // The desire date/time format is the "RFC822" format.
    CkHttpW_SetRequestHeader(http,L"Date",dateHdrVal);

    // ----------------------------------------------------------------
    // Digest header...
    CkCrypt2W_putHashAlgorithm(crypt,L"SHA256");
    CkCrypt2W_putEncodingMode(crypt,L"base64");
    // A GET request has no HTTP request body.  Therefore the payload is the empty string.
    payload = L"";
    payloadDigest = CkCrypt2W_hashStringENC(crypt,payload);
    sbDigestHdrVal = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbDigestHdrVal,L"SHA-256=");
    CkStringBuilderW_Append(sbDigestHdrVal,payloadDigest);
    CkHttpW_SetRequestHeader(http,L"digest",CkStringBuilderW_getAsString(sbDigestHdrVal));

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

    sbStringToSign = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbStringToSign,L"date: ");
    CkStringBuilderW_AppendLine(sbStringToSign,dateHdrVal,FALSE);
    CkStringBuilderW_Append(sbStringToSign,L"digest: ");
    CkStringBuilderW_AppendLine(sbStringToSign,CkStringBuilderW_getAsString(sbDigestHdrVal),FALSE);
    CkStringBuilderW_Append(sbStringToSign,L"x-request-id: ");
    CkStringBuilderW_Append(sbStringToSign,xRequestId);

    // ----------------------------------------------------------------
    // Sign with our private key...
    sbPrivKey = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbPrivKey,L"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDaAI6hllIAiJth");
    CkStringBuilderW_Append(sbPrivKey,L"ftLAUhMC2pfk97vrpXS4pKcRwgfIi9Rg+xa0Y3APjFbMYbx5cu70bByvrUMjEmni");
    CkStringBuilderW_Append(sbPrivKey,L"u/NkR6WN96sTy3PC5qEC29hLokMV4/TzmJGAUO+KpK2Z7ylZUd1qMkFngzl50mNs");
    CkStringBuilderW_Append(sbPrivKey,L"GzRX5D/BE+BJcMriCBK4sGIWm9DiK556zvF/Nv0j2cR8BHd2kI0OroYsPKWg7KSW");
    CkStringBuilderW_Append(sbPrivKey,L"0uVoxH7sGNeilVVGJYW7QMBo73OmitDQZvix/XzC6QBOoHxmTctIMzA6K1TW5ECt");
    CkStringBuilderW_Append(sbPrivKey,L"SKABg/KfWR3QdBdxcJCCxI1IkFupyvv3ygzSdEwW6YGVKWPG0eOtKs8SnXmdcjw6");
    CkStringBuilderW_Append(sbPrivKey,L"l9go4en5AgMBAAECggEAB8nsTqalwGIhFw8mbXuhNUFlGuek/arYLD6pv28swwQH");
    CkStringBuilderW_Append(sbPrivKey,L"7v0ZlxFUcCHF+iBl0PsDwZTZQ4ePtgGS6ehoLkWHCzb1lEv5E1YVG5qKNE2UUwRl");
    CkStringBuilderW_Append(sbPrivKey,L"fIyPakO6AzyV/UF3uzq7C+/GuXGNTKZxKewg5yD/DCFvKoCOpxu9u36FyqP/hw0S");
    CkStringBuilderW_Append(sbPrivKey,L"ADVlmp35/zoPDPZzu1j4FiCo0pJ9LwJcHxeJHopNAKDw9k6I4z/grskdgupsGzK2");
    CkStringBuilderW_Append(sbPrivKey,L"BiGiQ/+wmmO68/6Xa6KWfpr1PQ6ODJHgzZsdGCVi6Ebaqlj6BbsYWxP6h3lrsGt+");
    CkStringBuilderW_Append(sbPrivKey,L"LmHBaN2jCD6cDp+lihqFgnm8hfdv0lmbPilp71EDfwKBgQD6U8PBzZtN8yXm5WuS");
    CkStringBuilderW_Append(sbPrivKey,L"NL+/8q5GjNmeTJBSo1gM6Y8vOT4QAE147LbVuVBDwyHPoSrNejePae6Q14PswjBy");
    CkStringBuilderW_Append(sbPrivKey,L"T7B8DZ0OeQyGa3trrFg/ib7Vv4ZMvJqX9+WzBrzZsxTg7oCKHzmCR4vIRItKHH3z");
    CkStringBuilderW_Append(sbPrivKey,L"Wnnhqlo8ic2AZ2O43cdJosbO1wKBgQDe8UODOLu0vnHohOKeUqF3w/ZOB2+83/js");
    CkStringBuilderW_Append(sbPrivKey,L"YyUbSkzsGvHIwTjObuMUFTQvdMZ6IkIyJdfnDZIbvlBSD8tzL5iKFTNCK2nL1i4G");
    CkStringBuilderW_Append(sbPrivKey,L"iFr0CYLaHAlhJ5GEbTrTMDoJeBPerZq83HPrSa/Wb0xO18QTWsoVQPFfPFbbcQyI");
    CkStringBuilderW_Append(sbPrivKey,L"9ryJ2iIDrwKBgQC6kuAefG46ZPVk6K2KZUJdgDUgZC52a75NuW0RAqszmUiGiJM1");
    CkStringBuilderW_Append(sbPrivKey,L"g8ip9tq6BqAWrprGV0c93shusBKlzf5p1LdHXqYmeVY6gbWVhPipMrNHgN5KJ3BZ");
    CkStringBuilderW_Append(sbPrivKey,L"v+w1yNnMsErpcxne2HL2hPjMJTpj3GSLkm2xIlTrNhIyl9ydlr7IRUhENQKBgQCv");
    CkStringBuilderW_Append(sbPrivKey,L"i6HxbXa/90WSJTCcIcxqla8X+dsOCf3jhJ3vQy4Wq5C+1wZ35fCAG8Ifq/+so9Uj");
    CkStringBuilderW_Append(sbPrivKey,L"z5CVqqXlmpF8TFuSs2OVNuRJsg14J4nOMwgLKIIUZAcurQ10DN5I9Kx+UEK1EFXL");
    CkStringBuilderW_Append(sbPrivKey,L"aHsORdNjMfgQDO2jn9WHrr9gkg6CdB2+qyoCEfS+mQKBgBW08lcy9V5RzRWb/v/j");
    CkStringBuilderW_Append(sbPrivKey,L"xsc7ovmgAhCJhDeV7dPbx4HbFeoQJlbA8g1thdcFlcatSGyNDbvNE1GPSd4NhkpR");
    CkStringBuilderW_Append(sbPrivKey,L"Y6Hfv53kdEzjVkEtU8lUdL7HNVJqX7bU7oZlfbYcwxWQ1Gg8C1oLIAyEt71slQtd");
    CkStringBuilderW_Append(sbPrivKey,L"RiNYBRZTQe2F0wxbXnuUqLAw");

    privKey = CkPrivateKeyW_Create();
    success = CkPrivateKeyW_LoadPem(privKey,CkStringBuilderW_getAsString(sbPrivKey));
    if (success == FALSE) {
        wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(privKey));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        return;
    }

    rsa = CkRsaW_Create();
    success = CkRsaW_ImportPrivateKeyObj(rsa,privKey);
    if (success == FALSE) {
        wprintf(L"%s\n",CkRsaW_lastErrorText(rsa));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        return;
    }

    CkRsaW_putEncodingMode(rsa,L"base64");
    b64Signature = CkRsaW_signStringENC(rsa,CkStringBuilderW_getAsString(sbStringToSign),L"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. 
    cert = CkCertW_Create();
    success = CkCertW_SetFromEncoded(cert,CkStringBuilderW_getAsString(sbTppCert));
    if (success == FALSE) {
        wprintf(L"%s\n",CkCertW_lastErrorText(cert));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        CkCertW_Dispose(cert);
        return;
    }

    sbSigHdrVal = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sbSigHdrVal,L"keyId=\"");
    CkStringBuilderW_Append(sbSigHdrVal,CkCertW_serialDecimal(cert));
    CkStringBuilderW_Append(sbSigHdrVal,L"\",");
    CkStringBuilderW_Append(sbSigHdrVal,L"algorithm=\"rsa-sha256\",");
    CkStringBuilderW_Append(sbSigHdrVal,L"headers=\"date digest x-request-id\",");
    CkStringBuilderW_Append(sbSigHdrVal,L"signature=\"");
    CkStringBuilderW_Append(sbSigHdrVal,b64Signature);
    CkStringBuilderW_Append(sbSigHdrVal,L"\"");

    CkHttpW_SetRequestHeader(http,L"signature",CkStringBuilderW_getAsString(sbSigHdrVal));

    // ----------------------------------------------------------------
    // Add remaining headers...

    CkHttpW_SetRequestHeader(http,L"x-ibm-client-id",L"YOUR_APP_CLIENT_ID");
    CkHttpW_SetRequestHeader(http,L"accept",L"application/json");

    // ----------------------------------------------------------------
    // Add our certificate and key for mutual TLS 
    // (provide a registered X509 client certificate during TLS handhake)

    tlsCert = CkCertW_Create();
    success = CkCertW_LoadFromFile(tlsCert,L"qa_data/certs_and_keys/ING/example_client_tls.cer");
    if (success == FALSE) {
        wprintf(L"%s\n",CkCertW_lastErrorText(tlsCert));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        CkCertW_Dispose(cert);
        CkStringBuilderW_Dispose(sbSigHdrVal);
        CkCertW_Dispose(tlsCert);
        return;
    }

    bdPrivKey = CkBinDataW_Create();
    success = CkBinDataW_LoadFile(bdPrivKey,L"qa_data/certs_and_keys/ING/example_client_tls.key");
    if (success == FALSE) {
        wprintf(L"Failed to load example_client_tls.key\n");
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        CkCertW_Dispose(cert);
        CkStringBuilderW_Dispose(sbSigHdrVal);
        CkCertW_Dispose(tlsCert);
        CkBinDataW_Dispose(bdPrivKey);
        return;
    }

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

    tlsPrivKey = CkPrivateKeyW_Create();
    success = CkPrivateKeyW_LoadAnyFormat(tlsPrivKey,bdPrivKey,L"");
    if (success == FALSE) {
        wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(tlsPrivKey));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        CkCertW_Dispose(cert);
        CkStringBuilderW_Dispose(sbSigHdrVal);
        CkCertW_Dispose(tlsCert);
        CkBinDataW_Dispose(bdPrivKey);
        CkPrivateKeyW_Dispose(tlsPrivKey);
        return;
    }

    // Associate the private key with the certificate.
    success = CkCertW_SetPrivateKey(tlsCert,tlsPrivKey);
    if (success == FALSE) {
        wprintf(L"%s\n",CkCertW_lastErrorText(tlsCert));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        CkCertW_Dispose(cert);
        CkStringBuilderW_Dispose(sbSigHdrVal);
        CkCertW_Dispose(tlsCert);
        CkBinDataW_Dispose(bdPrivKey);
        CkPrivateKeyW_Dispose(tlsPrivKey);
        return;
    }

    success = CkHttpW_SetSslClientCert(http,tlsCert);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        CkCertW_Dispose(cert);
        CkStringBuilderW_Dispose(sbSigHdrVal);
        CkCertW_Dispose(tlsCert);
        CkBinDataW_Dispose(bdPrivKey);
        CkPrivateKeyW_Dispose(tlsPrivKey);
        return;
    }

    // ----------------------------------------------------------------
    // Finally, send the request...

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://api-sandbox.rabobank.nl/openapi/sandbox/payments/account-information/ais/v3/accounts",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        CkCertW_Dispose(cert);
        CkStringBuilderW_Dispose(sbSigHdrVal);
        CkCertW_Dispose(tlsCert);
        CkBinDataW_Dispose(bdPrivKey);
        CkPrivateKeyW_Dispose(tlsPrivKey);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbTppCert);
        CkCrypt2W_Dispose(crypt);
        CkDateTimeW_Dispose(dt);
        CkStringBuilderW_Dispose(sbDigestHdrVal);
        CkStringBuilderW_Dispose(sbStringToSign);
        CkStringBuilderW_Dispose(sbPrivKey);
        CkPrivateKeyW_Dispose(privKey);
        CkRsaW_Dispose(rsa);
        CkCertW_Dispose(cert);
        CkStringBuilderW_Dispose(sbSigHdrVal);
        CkCertW_Dispose(tlsCert);
        CkBinDataW_Dispose(bdPrivKey);
        CkPrivateKeyW_Dispose(tlsPrivKey);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    // 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;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"accounts");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        v_linksAccount = CkJsonObjectW_stringOf(jResp,L"accounts[i]._links.account");
        v_linksBalances = CkJsonObjectW_stringOf(jResp,L"accounts[i]._links.balances");
        v_linksTransactions = CkJsonObjectW_stringOf(jResp,L"accounts[i]._links.transactions");
        currency = CkJsonObjectW_stringOf(jResp,L"accounts[i].currency");
        iban = CkJsonObjectW_stringOf(jResp,L"accounts[i].iban");
        name = CkJsonObjectW_stringOf(jResp,L"accounts[i].name");
        resourceId = CkJsonObjectW_stringOf(jResp,L"accounts[i].resourceId");
        status = CkJsonObjectW_stringOf(jResp,L"accounts[i].status");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(jsonToken);
    CkStringBuilderW_Dispose(sbTppCert);
    CkCrypt2W_Dispose(crypt);
    CkDateTimeW_Dispose(dt);
    CkStringBuilderW_Dispose(sbDigestHdrVal);
    CkStringBuilderW_Dispose(sbStringToSign);
    CkStringBuilderW_Dispose(sbPrivKey);
    CkPrivateKeyW_Dispose(privKey);
    CkRsaW_Dispose(rsa);
    CkCertW_Dispose(cert);
    CkStringBuilderW_Dispose(sbSigHdrVal);
    CkCertW_Dispose(tlsCert);
    CkBinDataW_Dispose(bdPrivKey);
    CkPrivateKeyW_Dispose(tlsPrivKey);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

 

© 2000-2020 Chilkat Software, Inc. All Rights Reserved.