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.
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();
}