Xero Integration With Nest Js

 Xero  

Xero is a cloud based accounting software that provide invoice creation, expense tracking, bank transaction, financial reporting like feature for financial management.

 Xero go ?

  1. Create a xero account ( if not )
  2. log in 
  3. after login we will redirect to xero dashboard. 
  4. For create organization we can use top left side dropdown. 
  5. Select new organization or we can use 'Demo Company'. 
  6. Using top plue icon ( + ) we can create invoice , bill, contact, etc.
  7. We can customize dashboard as we want.
Xero developer

Create a new application 
  1. Go to 'My Apps' this section will have all App which we are created or we can create new app.
  2. Click 'New app' button and Enter app Name. 
  3. Choose Integration type ( Web app, Mobile and Desktop app, Custom connection )
  4. Enter company or application URL and Redirect Url.
App details section
  1. App details ( app basic details )
  2. Redirect URLs - ( after authentication where we will redirect with access-token and tenant Id ).
  3. configuration - we can get client id and client secret.
Playground
  1. Click Explore menu ( inside navbar ).
  2. In this section we can test the xero apis without any access token or authentication. 
  3. select organization and choose api to make request. we can add headers and query parameter. 
Postman Authentication 
  1. import  xero oAuth2.0 collection and set xero environment into postman. Link.

This type of collection you will got not click on "Xero OAuth 2.0" then go to the 'Authentication'  section scroll down and you will get "Configure new Token" section. 


fill this configurations to connect with you xero account.
  • Token Name : - it refer to identity name of access token.
  • Callback url :- This URL to which the user is redirected after they have successfully authenticated and approved access for your application.
Note :- Callback url is very important part of authentication. In the case of nest js i put the "localhost" url but not worked then i used ngrok it help to open any port on your route. Or you can checked or click Authorize using browser it will help to return postmon back when authentication is successful.
Important- Make sure putted same redirect url in configuration section on xero developer.
  • Auth Url :- https://login.xero.com/identity/connect/authorize  ( this is auth url which will help you to redirect login page on xero.
  • Access Token Url :- https://identity.xero.com/connect/token    
  • Client ID and Client secret :- Go to developer xero app click go to "my App" and select application and go to the configuration section here is your client id and client secret. 
  • scope :- "scope" refers to the permissions or access rights that an application requests from the user.  ( copy this and enter in scope - openid profile email accounting.transactions ).
scroll down and click Get New Access Token. 


You will redirect to your browser and after successful authentication will redirect to our postmon or application with access token, refresh token, tenent id... etc.
click Environment quick look button and set all config what you got after authentication.


create a new request fetch any api endpoint. Go to the type section and select Inherit auth from parent if you already set in parent or you can choose OAuth 2.0 to enter manually. 

Now you can access all Xero Api or endpoints.