Xero API Wrapper Update and Samples
Posted 29/01/2009 10:14:00 a.m. by Daniel in Computers
It’s been a while since I released my initial Xero API wrapper, and I have made a few changes since then, so I thought it’s time for a small release.
The code you checkout on Codeplex now has a sample application in which you can get a rough idea of how it fits together.
Note: This release is a source-only release. You will need to check the project out of source control. The wrapper will be going through a huge update in the next month or two with the new release of the API.
https://XeroLabs.svn.codeplex.com/svn
Changes
- Moved the ContactObjects to the default namespace – you can still call them the old way, but it will throw warnings.
- Changed the GetContacts() method to Get() to match naming standards. Again old will work, but it will throw errors.
- You can now pass the auth object in to the get methods meaning you don’t need to create the object first
- You can also create the auth object by passing in parameters instead of setting properties after it’s been created
Samples
Get All Contacts:
static Communication.XeroAuth auth = new Communication.XeroAuth(
"Network Key",
"Customer Key",
"https://networktest.xero.com/"
);
static void Main(string[] args)
{
ContactCollection collection = ContactCollection.Get(auth);
foreach (var contact in collection.Records)
{
Console.WriteLine(contact.Name);
}
Console.ReadKey();
}
Create New Contact
static Communication.XeroAuth auth = new Communication.XeroAuth(
"Provider Key",
"Customer Key",
"https://networktest.xero.com/"
);
static void Main(string[] args)
{
ContactRecord rec = new ContactRecord(auth);
rec.Name = "Daniel";
rec.EmailAddress = "name@example.com";
rec.Save();
}
The whole wrapper works in roughly the same way so it should be fairly simple to pickup from those two sample.
Have fun!