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
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Have you checked out the integration apps available on the Salesforce app exchange appexchange.salesforce.com, rather than going the bespoke route? One that I've used successfully in the past which integrates with xero is Breadwinner - appexchange.salesforce.com/…. It was easy to use and setup and allows two-way sync of invoices with clicks not code. – Jim Sep 29 '16 at 3:22
  • Breadwinner is a good one: appexchange.salesforce.com/… – Eric Sep 29 '16 at 3:27
  • yeah I even installed breadwinner. How breadwinner do the integration is the thing I want to accomplished. I just want to create my own. – Hope Sep 29 '16 at 3:32
  • @Hope - That question is the definition of "Too Broad". There is a reason many of these packages have been created. I would bet they have put thousands of hours into tuning it, coding of edge cases, coding for customer requirements, etc. Do you have that kinda of time? If so, better fire up your apex skills and get coding. When you have a specific question feel free to post it up. You did state you wanted a public application. Are we misunderstanding what you men using private and public in the way you did – Eric Sep 29 '16 at 4:30
  • @Eric yeah sorry for that. What i just want to know is that, if there is any good article or SDK I can use to start building what I want. For now, I already successfully connect to Xero using xero private application wherein, I need to create a salesforce certificate and upload it to xero to get the consumer key and other thing. Public application works different, it is quite user friendly wherein you automatically connect to xero by supplying your xero and username password as what is commonly happen to third party application. – Hope Sep 29 '16 at 5:05

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.

  • Very well said. I really appreciate it ++. – Hope Oct 7 '16 at 2:06

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.

Rough Process

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.

Possible Alternative

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.