Sample code for 30+ languages & platforms
Delphi DLL

Isabel Connect List Accounts

See more Ibanity Examples

Get a list of accounts.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonObject, Http;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
jsonToken: HCkJsonObject;
jsonStr: PWideChar;
jResp: HCkJsonObject;
respStatusCode: Integer;
id: PWideChar;
v_type: PWideChar;
metaPagingOffset: Integer;
metaPagingTotal: Integer;
i: Integer;
count_i: Integer;

begin
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 \
// --cert certificate.pem:qwertyuiop1 \
// --key private_key.pem  \
// -H "Authorization: Bearer access_token_1603365407" \
// -H "Accept: application/vnd.api+json"  

// 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.)
success := CkHttp_SetSslClientCertPfx(http,'qa_data/pfx/my_ibanity_certificate.pfx','my_pfx_password');
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

// Load the previously obtained access token.
jsonToken := CkJsonObject_Create();
success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/isabel_access_token.json');
if (success = False) then
  begin
    Memo1.Lines.Add('No existing access token.');
    Exit;
  end;

// 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');

jsonStr := CkHttp__quickGetStr(http,'https://api.ibanity.com/isabel-connect/accounts');
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_Load(jResp,jsonStr);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttp__lastResponseHeader(http));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "data": [
//     {
//       "id": "93ecb1fdbfb7848e7b7896c0f2d207aed3d8b4c1",
//       "type": "account"
//     }
//   ],
//   "meta": {
//     "paging": {
//       "offset": 0,
//       "total": 1
//     }
//   }
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

metaPagingOffset := CkJsonObject_IntOf(jResp,'meta.paging.offset');
metaPagingTotal := CkJsonObject_IntOf(jResp,'meta.paging.total');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'data');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    id := CkJsonObject__stringOf(jResp,'data[i].id');
    v_type := CkJsonObject__stringOf(jResp,'data[i].type');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(jsonToken);
CkJsonObject_Dispose(jResp);

end;