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

BrickLink OAuth1 using Chilkat REST

See more BrickLink Examples

Demonstrates sending an api.bricklink.com request with OAuth1 authentication using Chilkat REST.

Note: This example requires Chilkat v9.5.0.91 or greater (due to adjustments made within Chilkat to support bricklink OAuth1 needs).

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.OAuth1,
  Chilkat.Rest,
  Chilkat.StringBuilder,
  Chilkat.JsonObject;

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

procedure RunDemo;
var
  success: Boolean;
  oauth1: TOAuth1;
  rest: TRest;
  sbResponse: TStringBuilder;
  json: TJsonObject;

begin
  success := False;

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

  oauth1 := TOAuth1.Create;

  oauth1.ConsumerKey := 'Your Consumer Key';
  oauth1.ConsumerSecret := 'Your Consumer Secret';
  oauth1.Token := 'Your OAuth1 Token';
  oauth1.TokenSecret := 'Your Token Secret';
  oauth1.SignatureMethod := 'HMAC-SHA1';

  rest := TRest.Create;

  rest.SetAuthOAuth1(oauth1,False);

  success := rest.Connect('api.bricklink.com',443,True,True);
  if (success = False) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  sbResponse := TStringBuilder.Create;
  success := rest.FullRequestNoBodySb('GET','/api/store/v1/orders?direction=in',sbResponse);
  if (success = False) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  WriteLn('Response status code = ' + rest.ResponseStatusCode);

  json := TJsonObject.Create;
  json.LoadSb(sbResponse);
  json.EmitCompact := False;
  WriteLn(json.Emit());


  oauth1.Free;
  rest.Free;
  sbResponse.Free;
  json.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.