C
C
Isabel Connect Get Account
See more Ibanity Examples
Get the details for a specific account.Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkCert.h>
#include <C_CkPrivateKey.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkCert cert;
HCkPrivateKey privKey;
HCkJsonObject jsonToken;
const char *jsonStr;
HCkJsonObject jResp;
int respStatusCode;
const char *dataAttributesCountry;
const char *dataAttributesCurrency;
const char *dataAttributesDescription;
const char *dataAttributesFinancialInstitutionBic;
const char *dataAttributesHolderAddress;
const char *dataAttributesHolderAddressCountry;
const char *dataAttributesHolderName;
const char *dataAttributesReference;
const char *dataAttributesReferenceType;
const char *dataId;
const char *dataType;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_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 = CkCert_Create();
success = CkCert_LoadFromFile(cert,"qa_data/pem/my_ibanity_certificate.pem");
if (success == FALSE) {
printf("%s\n",CkCert_lastErrorText(cert));
CkHttp_Dispose(http);
CkCert_Dispose(cert);
return;
}
privKey = CkPrivateKey_Create();
success = CkPrivateKey_LoadEncryptedPemFile(privKey,"qa_data/pem/my_ibanity_private_key.pem","my_pem_password");
if (success == FALSE) {
printf("%s\n",CkPrivateKey_lastErrorText(privKey));
CkHttp_Dispose(http);
CkCert_Dispose(cert);
CkPrivateKey_Dispose(privKey);
return;
}
success = CkCert_SetPrivateKey(cert,privKey);
if (success == FALSE) {
printf("%s\n",CkCert_lastErrorText(cert));
CkHttp_Dispose(http);
CkCert_Dispose(cert);
CkPrivateKey_Dispose(privKey);
return;
}
success = CkHttp_SetSslClientCert(http,cert);
if (success == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkCert_Dispose(cert);
CkPrivateKey_Dispose(privKey);
return;
}
// Load the previously obtained access token.
jsonToken = CkJsonObject_Create();
success = CkJsonObject_LoadFile(jsonToken,"qa_data/tokens/isabel_access_token.json");
if (success == FALSE) {
printf("No existing access token.\n");
CkHttp_Dispose(http);
CkCert_Dispose(cert);
CkPrivateKey_Dispose(privKey);
CkJsonObject_Dispose(jsonToken);
return;
}
// This causes the "Authorization: Bearer ***" header to be added to the HTTP request.
CkHttp_putAuthToken(http,CkJsonObject_stringOf(jsonToken,"access_token"));
CkHttp_putAccept(http,"application/vnd.api+json");
CkHttp_SetUrlVar(http,"id","93ecb1fdbfb7848e7b7896c0f2d207aed3d8b4c1");
jsonStr = CkHttp_quickGetStr(http,"https://api.ibanity.com/isabel-connect/accounts/{$id}");
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkCert_Dispose(cert);
CkPrivateKey_Dispose(privKey);
CkJsonObject_Dispose(jsonToken);
return;
}
jResp = CkJsonObject_Create();
CkJsonObject_Load(jResp,jsonStr);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttp_getLastStatus(http);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttp_lastResponseHeader(http));
printf("Failed.\n");
CkHttp_Dispose(http);
CkCert_Dispose(cert);
CkPrivateKey_Dispose(privKey);
CkJsonObject_Dispose(jsonToken);
CkJsonObject_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 = CkJsonObject_stringOf(jResp,"data.attributes.country");
dataAttributesCurrency = CkJsonObject_stringOf(jResp,"data.attributes.currency");
dataAttributesDescription = CkJsonObject_stringOf(jResp,"data.attributes.description");
dataAttributesFinancialInstitutionBic = CkJsonObject_stringOf(jResp,"data.attributes.financialInstitutionBic");
dataAttributesHolderAddress = CkJsonObject_stringOf(jResp,"data.attributes.holderAddress");
dataAttributesHolderAddressCountry = CkJsonObject_stringOf(jResp,"data.attributes.holderAddressCountry");
dataAttributesHolderName = CkJsonObject_stringOf(jResp,"data.attributes.holderName");
dataAttributesReference = CkJsonObject_stringOf(jResp,"data.attributes.reference");
dataAttributesReferenceType = CkJsonObject_stringOf(jResp,"data.attributes.referenceType");
dataId = CkJsonObject_stringOf(jResp,"data.id");
dataType = CkJsonObject_stringOf(jResp,"data.type");
CkHttp_Dispose(http);
CkCert_Dispose(cert);
CkPrivateKey_Dispose(privKey);
CkJsonObject_Dispose(jsonToken);
CkJsonObject_Dispose(jResp);
}