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

Adobe Analytics Reporting API (1.4)

See more HTTP Misc Examples

Demonstrates a simple POST of JSON to the Adobe Analytics Reporting API (v1.4)

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.CkDateTime,
  Chilkat.Prng,
  Chilkat.HttpResponse,
  Chilkat.StringBuilder,
  Chilkat.JsonObject,
  Chilkat.Crypt2,
  Chilkat.Http;

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

procedure RunDemo;
var
  success: Boolean;
  url: string;
  json: TJsonObject;
  http: THttp;
  dt: TCkDateTime;
  timecreated: string;
  prng: TPrng;
  nonce: string;
  secret: string;
  sb: TStringBuilder;
  crypt: TCrypt2;
  digest: string;
  sbNonce: TStringBuilder;
  resp: THttpResponse;

begin
  success := False;

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

  //  In this example, replace "rsid" with your report suite id, and update the URL to use the correct endpoint
  url := 'https://api.omniture.com/admin/1.4/rest/?method=Report.Queue';

  json := TJsonObject.Create;
  json.UpdateString('reportDescription.reportSuiteID','rsid');
  json.UpdateString('reportDescription.dateGranularity','hour');

  http := THttp.Create;

  dt := TCkDateTime.Create;
  dt.SetFromCurrentSystemTime();
  timecreated := dt.GetAsTimestamp(False);

  prng := TPrng.Create;
  nonce := prng.GenRandom(12,'hex');

  secret := 'SECRET';

  sb := TStringBuilder.Create;
  sb.Append(nonce);
  sb.Append(timecreated);
  sb.Append(secret);

  crypt := TCrypt2.Create;
  crypt.HashAlgorithm := 'sha1';
  crypt.EncodingMode := 'base64';
  digest := crypt.HashStringENC(sb.GetAsString());

  sbNonce := TStringBuilder.Create;
  sbNonce.Append(nonce);
  sbNonce.Encode('base64');

  sb.Clear();
  sb.Append('UsernameToken Username="USERNAME", PasswordDigest="');
  sb.Append(digest);
  sb.Append('", Nonce="');
  sb.Append(sbNonce.GetAsString());
  sb.Append('", Created="');
  sb.Append(timecreated);
  sb.Append('"');

  WriteLn(sb.GetAsString());

  http.SetRequestHeader('X-WSSE',sb.GetAsString());

  resp := THttpResponse.Create;
  success := http.HttpJson('POST',url,json,'text/json',resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  WriteLn('Http Status code: ' + resp.StatusCode);
  WriteLn('JSON response:');
  WriteLn(resp.BodyStr);


  json.Free;
  http.Free;
  dt.Free;
  prng.Free;
  sb.Free;
  crypt.Free;
  sbNonce.Free;
  resp.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.