Home

Awesome

delphiXERO

XERO accounting API for Delphi

http://developer.xero.com/

Supports Delphi Sydney 10.4.2

This is a work in progress so design and requirements may change.

License

Use this source code in open source or commercial software. You do not need to provide any credit. However please provide any fixes or enhancements to keep the component alive and helpful to everyone

Thanks

ToDo



#Components#

TXEROAppDetails

Store XERO App Details

XEROAppDetails.ClientID := '4D914DECC5F34C4D882F76F0....';

TXEROAuthenticatorPKCE

OAuth2 PKCE Authentication ([https://developer.xero.com/documentation/oauth2/pkce-flow])

This component will launch the authentication URL and will start a http:localhost:{port} server for authentication response

By default the HTTP Server attempts to start on port 58985, 58986 or 58987

The default scope is 'openid profile email accounting.transactions accounting.contacts accounting.settings'

Use OnXEROAuthenticationURL to launch default browser or show within a browser in your application (NOTE: TWebBrowser IE Mode does not work)

XEROAuthenticatorPKCE.OnXEROAuthenticationURL :=  { example OnXEROAuthenticationURL(ASender: TObject; AURL: string) }
XEROAuthenticatorPKCE.OnXEROAuthenticationComplete :=  { example OnXEROAuthenticationComplete(ASender: TObject; ASuccess: Boolean) }
XEROAuthenticatorPKCE.Scope := 'openid profile email accounting.transactions accounting.contacts accounting.settings';
XEROAuthenticatorPKCE.Login;

Upon login FXEROAuthenticatorPKCE.AuthToken and XEROAuthenticatorPKCE.Tenants will be populated

TXEROApiJSON

Provide a simple interface for calling the XERO API

Get

var
 LAPI: TXEROApiJSON;
begin
  LAPI := TXEROApiJSON.Create(nil);
  try
	LAPI.XEROAppDetails := FXEROAppDetails;
	LAPI.TenantID := '06c6ccf8-bd57-4d2f-a36e-396b2af59f24';
	LJSON := LAPI.Get('Contacts','page=1');
  finally
	FreeAndNil(LAPI);
  end;
end;

Post

var
 LAPI: TXEROApiJSON;
begin
  LAPI := TXEROApiJSON.Create(nil);
  try
	LAPI.XEROAppDetails := FXEROAppDetails;
	LAPI.TenantID := '06c6ccf8-bd57-4d2f-a36e-396b2af59f24';
	LJSON := LAPI.Post('Contacts','[JSON data]');
  finally
	FreeAndNil(LAPI);
  end;
end;