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

Quickbooks Revoke OAuth2 Token

See more QuickBooks Examples

Demonstrates how to revoke a QuickBooks OAuth2 access token.

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;
  jsonToken: TJsonObject;
  http: THttp;
  json: TJsonObject;
  url: string;
  resp: THttpResponse;

begin
  success := False;

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

  //  This example assumes we previously obtained an OAuth2 access token for QuickBooks.

  jsonToken := TJsonObject.Create;
  success := jsonToken.LoadFile('qa_data/tokens/qb-access-token.json');
  if (success <> True) then
    begin
      WriteLn('Failed to load qb-access-token.json');
      Exit;
    end;

  //  The access token JSON looks something like this:

  //  {
  //    "expires_in": 3600,
  //    "x_refresh_token_expires_in": 8726400,
  //    "refresh_token": "L011546037639r ... 3vR2DrbOmg0Sdagw",
  //    "access_token": "eyJlbmMiOiJBMTI4Q0 ... oETJEMbeggg",
  //    "token_type": "bearer"
  //  }

  //  This code sends the following request:

  //  POST https://developer.api.intuit.com/v2/oauth2/tokens/revoke HTTP/1.1
  //  Accept: application/json
  //  Authorization: Basic UTM0dVB...wM1d2
  //  Content-Type: application/json
  //  
  //  {
  //      "token": "{bearerToken or refreshToken}"
  //  }

  //  Use this online tool to generate HTTP code from a sample request: 
  //  Generate Code from a Sample HTTP Request

  http := THttp.Create;
  http.SetRequestHeader('Accept','application/json');
  http.BasicAuth := True;
  http.Login := 'QUICKBOOKS-CLIENT-ID';
  http.Password := 'QUICKBOOKS-CLIENT-SECRET';

  json := TJsonObject.Create;
  json.UpdateString('token',jsonToken.StringOf('access_token'));

  url := 'https://developer.api.intuit.com/v2/oauth2/tokens/revoke';
  resp := THttpResponse.Create;
  success := http.HttpJson('POST',url,json,'application/json',resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  WriteLn('Response status code = ' + resp.StatusCode);
  WriteLn('Response body:');
  WriteLn(resp.BodyStr);


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