Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Datev - Get a List of Clients

See more Datev Examples

Demonstrates how to get a list of clients in the accounting:clients Datev API.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.JsonArray,
  Chilkat.HttpResponse,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  queryParams: TJsonObject;
  resp: THttpResponse;
  jarr: TJsonArray;
  json: TJsonObject;
  client_number: Integer;
  consultant_number: Integer;
  id: string;
  name: string;
  j: Integer;
  count_j: Integer;
  k: Integer;
  count_k: Integer;
  strVal: string;
  i: Integer;
  count_i: Integer;

begin
  success := False;

  http := THttp.Create;

  //  Implements the following CURL command:

  //  curl --request GET \
  //    --url "https://accounting-clients.api.datev.de/platform/v2/clients?filter=REPLACE_THIS_VALUE&skip=REPLACE_THIS_VALUE&top=REPLACE_THIS_VALUE" \
  //    --header "Authorization: Bearer REPLACE_BEARER_TOKEN" \
  //    --header "X-Datev-Client-ID: clientId" \
  //    --header "accept: application/json;charset=utf-8"

  //  Use the following online tool to generate HTTP code from a CURL command
  //  Convert a cURL Command to HTTP Source Code

  queryParams := TJsonObject.Create;
  //  ignore = queryParams.UpdateString("filter","REPLACE_THIS_VALUE");
  //  ignore = queryParams.UpdateString("skip","REPLACE_THIS_VALUE");
  //  ignore = queryParams.UpdateString("top","REPLACE_THIS_VALUE");

  //  Adds the "Authorization: Bearer REPLACE_BEARER_TOKEN" header.
  http.AuthToken := 'REPLACE_BEARER_TOKEN';
  http.SetRequestHeader('accept','application/json;charset=utf-8');
  http.SetRequestHeader('X-Datev-Client-ID','DATEV_CLIENT_ID');

  resp := THttpResponse.Create;
  success := http.HttpParams('GET','https://accounting-clients.api.datev.de/platform-sandbox/v2/clients',queryParams,resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  WriteLn(resp.StatusCode);
  WriteLn(resp.BodyStr);

  jarr := TJsonArray.Create;

  //  Insert code here to load the above JSON array into the jarr object.
  jarr.Load(resp.BodyStr);

  i := 0;
  count_i := jarr.Size;
  while i < count_i do
    begin
      json := jarr.ObjectAt(i);
      client_number := json.IntOf('client_number');
      consultant_number := json.IntOf('consultant_number');
      id := json.StringOf('id');
      name := json.StringOf('name');
      j := 0;
      count_j := json.SizeOfArray('services');
      while j < count_j do
        begin
          json.J := j;
          name := json.StringOf('services[j].name');
          k := 0;
          count_k := json.SizeOfArray('services[j].scopes');
          while k < count_k do
            begin
              json.K := k;
              strVal := json.StringOf('services[j].scopes[k]');
              k := k + 1;
            end;

          j := j + 1;
        end;

      json.Free;
      i := i + 1;
    end;



  http.Free;
  queryParams.Free;
  resp.Free;
  jarr.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.