Working with the AccountRight/ new Essentials API
There are a few important core classes that require some detail before jumping straight into the code snippets and examples, these are covered off in the table below:
Class | Description |
ApiConfiguration |
The APIConfiguration is a simple class container that allows you to hold basic API configuration properties for you application. These include the APIs base url which can consist of: - http://localhost:8080/accountright for localhost - http://[IP ADDRESS OF COMPUTER TO ACCESS]:8080/accountright/ for network mode - https://api.myob.com/accountright for the cloud There are additional properties for the cloud apiBaseUrl including clientId, clientSecret and redirectUrl which are all related to OAuth authentication. public ApiConfiguration(string clientId, string clientSecret, string redirectUrl, string apiBaseUrl =
|
CompanyFileService |
A service class that is used to fetch all available company files. The 3 main parameters of note here are: - configuration (configuration required to communicate with the API service) - webRequestFactory (leave as null but can provide a mock class for automation testing purposes) - keyService (implementation of a service that stores tokens required for OAuth and the cloud apiBaseUrl) public CompanyFileService(IApiConfiguration configuration, IWebRequestFactory webRequestFactory = null, IOAuthKeyService
|
CompanyFileCredentials |
Another simple class container which stores company file credentials. These are separate from OAuth and are the equivalent of the AccountRight company file login details. Initialise an instance of this class to pass both the username and password in string format. If the client has linked their linked their my.myob log in to the company file sign in details then should be passed as either empty or null. public CompanyFileCredentials(string username, string password);
|
SimpleOAuthKeyService |
A simple OAuth key service that uses the IOAuthKeyService interface for classes that will store and retrieve OAuthTokens, this is used in memory only so it will not store tokens between sessions, other storage options can be implemented to extend this. public class SimpleOAuthKeyService : IOAuthKeyService |
OAuthService |
Service class that provides the available interactions with the OAuth server, this includes instantiating the OAuth configuration to which you can retrieve and refresh OAuth tokens required to communicate with the cloud apiBaseUrl. public OAuthService(IApiConfiguration configuration, IWebRequestFactory factory = null); public OAuthTokens GetTokens(string code); //(Synchronous) public OAuthTokens RenewTokens(OAuthTokens oauthTokens); //(Synchronous) |
OAuthTokens |
A class for OAuth tokens that includes methods that initialise and determine if an access token has expired as well as the ability to calculate a tokens expiration. |