Whenever we talk about integration, the very important thing is how securely connect to the third party system and then make the communication secure.
Hi #Trailblazers,
Welcome to my blog. In this blog post, we will learn how to integrate Salesforce with Xero.
Whenever we talk about integration, the very important thing is how securely connect to the third party system and then make the communication secure.
You can use below link to know all about Xero Authentication. Note: – Xero Uses OAuth 2.0 and OAuth 1.0 for authentication and we will use OAuth 2.0
https://developer.xero.com/documentation/sdks-and-tools/tools/postman/#steps-to-get-up-and-running
Navigate to This Link and then click on New App
Go to the Xero developer portal and create an OAuth2 app.
If you haven’t already signed up for a xero account you can do so here.
Use the following values:

Then:

Once you have created the Connected Application in Xero, now the time is to Create the Auth. Provider in Salesforce
Once you have created the Auth. Provider and Updated the callback URL in Xero Connected Application. Now, let’s created the Named Credentials as this will be used to Authenticate Xero with Salesforce
Make sure your named credentials looks like below image.
For Scope use below values
| offline_access accounting.settings openid profile email accounting.transactions accounting.transactions.read accounting.contacts |

To test the integration and make sure that this is working fine. Run the below code from the developer console
HttpRequest request = new HttpRequest();
request.setMethod('GET');
request.setEndpoint( 'callout:Xero/'+'connections' );
request.setHeader('Accept', 'application/json');
request.setHeader('xero-tenant-id', '');
HttpResponse response = new HttpResponse();
response = new Http().send(request);
System.debug(' \n '+ response.getStatusCode() );
System.debug(' \n '+ response.getBody() );
After executing the code you must see a 200 as status code. See the image below

Below is the complete code for your reference
Note: – XeroUtilApi class is the main Class which is using XeroAPICalloutService class to make the callouts to Xero Org.
Thanks for reading 🙂 Happy Learning