Unicode C
Unicode C
Isabel Connect Get Account
See more Ibanity Examples
Get the details for a specific account.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkCertW.h>
#include <C_CkPrivateKeyW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkCertW cert;
HCkPrivateKeyW privKey;
HCkJsonObjectW jsonToken;
const wchar_t *jsonStr;
HCkJsonObjectW jResp;
int respStatusCode;
const wchar_t *dataAttributesCountry;
const wchar_t *dataAttributesCurrency;
const wchar_t *dataAttributesDescription;
const wchar_t *dataAttributesFinancialInstitutionBic;
const wchar_t *dataAttributesHolderAddress;
const wchar_t *dataAttributesHolderAddressCountry;
const wchar_t *dataAttributesHolderName;
const wchar_t *dataAttributesReference;
const wchar_t *dataAttributesReferenceType;
const wchar_t *dataId;
const wchar_t *dataType;
success = FALSE;
// 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 -X GET https://api.ibanity.com/isabel-connect/accounts/93ecb1fdbfb7848e7b7896c0f2d207aed3d8b4c1 \
// --cert certificate.pem:qwertyuiop1 \
// --key private_key.pem \
// -H "Authorization: Bearer access_token_1603365407" \
// -H "Accept: application/vnd.api+json"
// Other Chilkat examples for Ibanity show how to set the SSL client certificate using the .pfx.
// This example will demonstrate using the PEM files.
cert = CkCertW_Create();
success = CkCertW_LoadFromFile(cert,L"qa_data/pem/my_ibanity_certificate.pem");
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkHttpW_Dispose(http);
CkCertW_Dispose(cert);
return;
}
privKey = CkPrivateKeyW_Create();
success = CkPrivateKeyW_LoadEncryptedPemFile(privKey,L"qa_data/pem/my_ibanity_private_key.pem",L"my_pem_password");
if (success == FALSE) {
wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(privKey));
CkHttpW_Dispose(http);
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
return;
}
success = CkCertW_SetPrivateKey(cert,privKey);
if (success == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkHttpW_Dispose(http);
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
return;
}
success = CkHttpW_SetSslClientCert(http,cert);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
return;
}
// Load the previously obtained access token.
jsonToken = CkJsonObjectW_Create();
success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/isabel_access_token.json");
if (success == FALSE) {
wprintf(L"No existing access token.\n");
CkHttpW_Dispose(http);
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
CkJsonObjectW_Dispose(jsonToken);
return;
}
// This causes the "Authorization: Bearer ***" header to be added to the HTTP request.
CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token"));
CkHttpW_putAccept(http,L"application/vnd.api+json");
CkHttpW_SetUrlVar(http,L"id",L"93ecb1fdbfb7848e7b7896c0f2d207aed3d8b4c1");
jsonStr = CkHttpW_quickGetStr(http,L"https://api.ibanity.com/isabel-connect/accounts/{$id}");
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
CkJsonObjectW_Dispose(jsonToken);
return;
}
jResp = CkJsonObjectW_Create();
CkJsonObjectW_Load(jResp,jsonStr);
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_lastResponseHeader(http));
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(jResp);
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": {
// "attributes": {
// "country": "BE",
// "currency": "EUR",
// "description": "current account",
// "financialInstitutionBic": "KREDBEBB",
// "holderAddress": "STREET NUMBER, ZIPCODE CITY",
// "holderAddressCountry": "BE",
// "holderName": "COMPANY",
// "reference": "BE96153112434405",
// "referenceType": "IBAN"
// },
// "id": "93ecb1fdbfb7848e7b7896c0f2d207aed3d8b4c1",
// "type": "account"
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
dataAttributesCountry = CkJsonObjectW_stringOf(jResp,L"data.attributes.country");
dataAttributesCurrency = CkJsonObjectW_stringOf(jResp,L"data.attributes.currency");
dataAttributesDescription = CkJsonObjectW_stringOf(jResp,L"data.attributes.description");
dataAttributesFinancialInstitutionBic = CkJsonObjectW_stringOf(jResp,L"data.attributes.financialInstitutionBic");
dataAttributesHolderAddress = CkJsonObjectW_stringOf(jResp,L"data.attributes.holderAddress");
dataAttributesHolderAddressCountry = CkJsonObjectW_stringOf(jResp,L"data.attributes.holderAddressCountry");
dataAttributesHolderName = CkJsonObjectW_stringOf(jResp,L"data.attributes.holderName");
dataAttributesReference = CkJsonObjectW_stringOf(jResp,L"data.attributes.reference");
dataAttributesReferenceType = CkJsonObjectW_stringOf(jResp,L"data.attributes.referenceType");
dataId = CkJsonObjectW_stringOf(jResp,L"data.id");
dataType = CkJsonObjectW_stringOf(jResp,L"data.type");
CkHttpW_Dispose(http);
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
CkJsonObjectW_Dispose(jsonToken);
CkJsonObjectW_Dispose(jResp);
}