I am trying to connect my salesforce instance to Xero. For now, I successfully connect my salesforce instance to xero using private application. But what I want at the moment is to connect to xero using public application. Does anyone of you has an idea about this? Or any good article to connect salesforce to xero instance using xero public application?
closed as off-topic by Adrian Larson♦, Mohith Shrivastava, Boris Bachovski, Sebastian Kessel, Himanshu Oct 16 '16 at 19:28
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Adrian Larson, Mohith Shrivastava, Boris Bachovski, Sebastian Kessel, Himanshu
Breadwinner here! Happy to help if we can.
You said you want to do a Public application, but I'd suggest you consider a Private Application if you want to mimic our functionality.
As you can see here, https://developer.xero.com/documentation/getting-started/api-application-types/, there are in fact three types of applications. We're a Partner application (also known as Public Partner), which gives us long term access. We need that to run our hourly update to pull data from Xero
A traditional Public app requires constant verification, as the token expires after 30 minutes. If you want your sync to run in the background, or have it go through a specific Xero user regardless of who is attempting this in Salesforce, a Public app will be problematic. You'll constantly have to have people signing in to Xero and they will need the correct authentication (usually, Xero Admin is required).
So, if you want something to run in the middle of the night, or be used by people without Xero Admin rights, then I'd opt for a Private Application. Once established, a Private Application can maintain that connection forever.
@Hope - the user friendliness of the Public application is, in my mind, completely negated for apps that require background syncing. Public Apps are better for occasional use connections.
This article explains how to create a Private App. https://developer.xero.com/documentation/getting-started/private-applications/
One tip - the expiration date of your public-private key pair is set by you. So something in the year 2150 is a pretty safe bet :-)
Also, this step can be a bit tricky. We used a Private model initially in our app and this was something that one of our developers just couldn't solve after two days. We gave it to another developer and they got it working in a day or so. Other people seem to struggle with this step, judging by the threads on Stack Exchange.
As for @Eric's comment, yes, you're completely right! In fact, "thousands of hours" is just the start. We don't track developer time that closely, but I'd estimate somewhere on the order of 16 developer years have gone into our integration.
One more general bit of advice - be aware that Xero has a hard limit of 1000 API calls a day, Salesforce has a 3mb upper limit for REST calls, and Salesforce can generally only do 10 REST calls in a batch. So even if you connect successfully, it's a very difficult juggling act to get everything without hitting limits. You might think this is solved if you use the Xero Paging API, but that's only available for Invoices, not for Credit Notes. And, with more than 1000 invoices you're above the Salesforce 10-per-batch-limit. So you'll have to communicate with Xero using both the Paging and Non-Paging API. One way to solve this is to build out middleware that work around these various limits.
The Xero documentation does appear to be quite light on information on how to go about this, but it appears that they just use the OAuth 1.0 standard.
You'll have to follow the setup steps in the documentation to setup an application, and then develop a combination of Apex and Visualforce/Lightning to provide the user with a button that opens up the authentication URL for Xero.
It's been a while since I went through this, so this may not be 100% correct, but the gist of the process is the following:
First you'll have to get an unauthorized request token using a callout from Apex, then redirect the user to the authentication url using the token as a parameter. You'll then have to implement an Apex webservice that can be used for the callback url to know when the request token has been authorized.
Once that happens you can swap the request token for an access token which can then be used when making requests to their API.
Depending on your use case, you might find that you can use Named Credentials but I think they only support OAuth 2.0 so that might be a non-starter. If you only need to use one Xero user for all the integration work then using the named principal option in these could make life a lot easier for you.