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

SugarCRM Logout

See more SugarCRM Examples

Demonstrates how to logout of a session.

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

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

procedure RunDemo;
var
  success: Boolean;
  rest: TRest;
  sbReq: TStringBuilder;
  sbJson: TStringBuilder;
  json: TJsonObject;

begin
  success := False;

  rest := TRest.Create;

  success := rest.Connect('your.site.domain',443,True,True);
  if (success <> True) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  rest.AddHeader('Cache-Control','no-cache');
  rest.AddHeader('OAuth-Token','<access_token>');

  sbReq := TStringBuilder.Create;

  sbJson := TStringBuilder.Create;
  success := rest.FullRequestSb('POST','/rest/v10/oauth2/logout',sbReq,sbJson);
  if (success <> True) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  if (rest.ResponseStatusCode <> 200) then
    begin
      WriteLn('Received error response code: ' + rest.ResponseStatusCode);
      WriteLn('Response body:');
      WriteLn(sbJson.GetAsString());
      Exit;
    end;

  json := TJsonObject.Create;
  json.LoadSb(sbJson);

  //  The following code parses the JSON response.
  //  A sample JSON response is shown below the sample code.

  success := json.BoolOf('success');

  //  A sample JSON response body that is parsed by the above code:

  //  {
  //    "success": true
  //  }

  WriteLn('Example Completed.');


  rest.Free;
  sbReq.Free;
  sbJson.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.