Xero API compiling the C# code sample from source for Private Applications

1. In a browser go to the XeroAPI/Xero-Net github site and "Download Zip"
2. Extract the zip file
3. Open Visual Studio and choose: File->Open/Project Solution
4. Navigate to the location where you unzipped the file
5. Choose the file "Xero.API.sln" and click open
6. Choose Build->Build Solution -this will generate the .dll files
7. Close the solution in Visual Studio: File->Close Solution
8. Create a new Project in Visual Studio: File->New->Project
9. Templates->Visual C#->Windows Desktop->Console Application
10. In "Solutions Explorer" window Right click on "References"

11. Choose "Add Reference" Choose "browse" on left menu

12. Press the "Browse" button bottom right

13.Navigate to the location of  the unzipped file then navigate deeper to Xero-Net-master->Xero.Api.Example.Applications->bin->Debug, select both the Xero.Api.dll & Xero.Api.Example.Applications.dll files and click "Add"

14. Make sure both are selected  in the "Reference Manager" list and click "Ok"

15. Now when you expand "references" you'll see Xero.Api & Xero.Api.Example.Applications in the list

16. Add the following lines to the top of your Program.cs file

using System.Security.Cryptography.X509Certificates;
using Xero.Api;
using Xero.Api.Core;
using Xero.Api.Example.Applications;
using Xero.Api.Example.Applications.Private;
using Xero.Api.Infrastructure.OAuth;
using Xero.Api.Serialization;

17. Add the following code to your main() function - replace with your key locations, client Ids & Keys etc (if you need more help regarding creating the key/secret on api.xero.com see PHP - Xero API getting the PHP code sample working for Private Applications if you need help on creating the .pxf file and password see C# - Xero API getting the C# code sample working for Private Applications with NuGet

            // Private Application Sample
            X509Certificate2 cert = new X509Certificate2(@"C:OpenSSL-Win32binpublic_privatekey.pfx", "testitout");
            var private_app_api = new XeroCoreApi("https://api.xero.com", new PrivateAuthenticator(cert),
                new DefaultMapper(), new DefaultMapper());        
            var org = private_app_api.Organisation;
            Console.WriteLine("Org Name: " + org.Name);
            var invoices = private_app_api.Invoices.OrderByDescending("Total").Find();
            Console.WriteLine("There are "+invoices.Count()+" Invoices, the 5 biggest are:");
            for (int i=0;i<5;i++)  //just print first 5 invoices for testing
                var myinvoice = invoices.ElementAt(i);
                Console.WriteLine(myinvoice.Contact.Name + " " + myinvoice.Total);
             var invoices = private_app_api.Invoices
                 .ModifiedSince(new DateTime(2013, 1, 31))
                 .Where("Total > 3500.0")
                 .And("Total < 10000.0")
            foreach (var myinvoice in invoices)
                Console.WriteLine(myinvoice.Contact.Name + " " + myinvoice.Total);
            var user = new ApiUser { Name = Environment.MachineName };

18. Choose Debug->Start Without Debugging and you'll get the following popup

Make a Comment

Website and Software Development Services
Tweed Heads & Southern Gold Coast

Our network of experienced computer programmers can develop custom software solutions in any language on any platform.

Our Talents

Freelance Power

We maintain a network of local freelance computer programmers that we place in teams to match project requirements. This gives us expertise in a broad range of industries, languages & platforms

Fix, Upgrade or New?

We can fix broken legacy systems, plan and oversee a difficult upgrade, add or unlock new features to your existing software. Or install and set-up new systems from scratch, including hardware and software


We can build solutions fast, Software as a Service (Saas), apps, web applications, desktop software, Minimum Viable Product using Agile Development practices


We can build simple to complex websites, we can deliver the whole package including site design, branding, logos, domains and hosting


C/C++, Java, JavaScript,
Python, Swift, Meteor,
Objective C


MongoDB, NoSQL


Linux, Mac, Windows, iPhone, Android, Smart Phones, Tablets


Wordpress, Drupal, Magento, Moodle, Sharepoint Online, Office 365