Please ignore some of the weird styles, doing a big HTML5 upgrade, and it's not quite done yet.

Daniel's Blog

The ramblings of a 22 year old guy.

Xero API Wrapper

Over the last few days I have been writing a small Xero API Wrapper for the new API. It pretty much takes care of requesting the XML from the API, parsing it, and returning populated objects – Saving you from doing it all manually. You can even save objects back to Xero!

The API hasn’t been fully released yet, but if you are busting to try it out, you can email network@xero.com to request an API Key.

Download Here

Setup

Before you can make any request, you will need to setup a new XeroAuth object. You will need to provide it with your API Key, Customer Key, and URL you wish to you. You only have to set this up once as you can reuse the object.

Xero.API.Communication.XeroAuth Auth = new Xero.API.Communication.XeroAuth();

Auth.CustomerKey = "Customer Key";
Auth.ProviderKey = "Your Provider Key";
Auth.URL = "https://networktest.xero.com/";

Each new object you use will need to have the its Auth property setup like the following

Xero.API.Object.Auth = Auth;

Using

Hopefully everything is fairly self explanatory. Use the Get() method to get objects from Xero, use the Save() method to save them back. All properties in each class match up to the Xero API XML.

Sample Code

public static Xero.API.Communication.XeroAuth Auth = new Xero.API.Communication.XeroAuth();
public void PrintContactName() {
     Auth.CustomerKey = "Customer Key";
     Auth.ProviderKey = "Provider Key";
     Auth.URL = "https://networktest.xero.com/";

     Xero.API.ContactCollection.Auth = Auth;
     Xero.API.ContactCollection Collection = Xero.API.ContactCollection.GetContacts();
     
     foreach (var contact in Collection.Records) {
           Console.WriteLine("Contact Name: " + contact.Name);
     }
     Console.ReadKey();
}
Post a comment
Comments
Thanks for this, the API looks great! I was looking for documentation on the codeplex site and then found your blog post via google. This makes my life [i]much[/i] easier. Cheers, Royce
Thanks! I will be releasing a new version sometime in the next month or two as there are alot of new API features coming out! I will do my best to keep it fully code compatible