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

qa.factura1.com.co Obtain Auth Token

See more HTTP Misc Examples

Demonstrates how to send a JSON POST to get an authenticataion token for qa.factura1.com.co

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.HttpResponse,
  Chilkat.JsonObject;

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

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  json: TJsonObject;
  resp: THttpResponse;
  jsonResp: TJsonObject;

begin
  success := False;

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

  http := THttp.Create;

  //  Build the following JSON
  //  {
  //    "password": "MY_PASSWORD",
  //    "username": "MY_USERNAME"
  //  }

  json := TJsonObject.Create;
  json.EmitCompact := False;
  json.UpdateString('password','MY_PASSWORD');
  json.UpdateString('username','MY_USERNAME');

  resp := THttpResponse.Create;
  success := http.HttpJson('POST','https://qa.factura1.com.co/v2/auth',json,'application/json',resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  jsonResp := TJsonObject.Create;
  jsonResp.EmitCompact := False;
  jsonResp.Load(resp.BodyStr);

  WriteLn(jsonResp.Emit());

  WriteLn('Access token: ' + jsonResp.StringOf('token'));


  http.Free;
  json.Free;
  resp.Free;
  jsonResp.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.