Xero API Wrapper

Posted at 09:20 p.m. on 27/11/2008 by Daniel

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 Comment
Name
Email Address
Website (Optional)
Comment
- Your comment will be moderated before it shows up.

Posted By Royce Fullerton at on 28/01/2009

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

Posted By Daniel at on 28/01/2009

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