XERO accounting API for Delphi
Supports Delphi Sydney 10.4.2
- Older versions may work but this has not been tested
- RIO: Testing in RIO so far has not worked, OAuth2 authentication would fail, possibly in CodeChallenge generation
This is a work in progress so design and requirements may change.
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
- Michael (https://github.com/frogonwheels)
- Access Token JWT decode (delphi-jose-jwt?)
- Expand API modules for all areas of API
- Option for URL to open in inbuilt Edge browser
#Components#
Store XERO App Details
XEROAppDetails.ClientID := '4D914DECC5F34C4D882F76F0....';
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
Provide a simple interface for calling the XERO API
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;
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;