Write .net against XERO


Useful Links:

Steps to Get Started

Follow these steps.

Create SSL Certification

  1. Install Open SSL from link provided above.
  2. Open command prompt (Run as administrator)
  3. Navigate to bin folder of openssl e.g. “C:\OpenSSL-Win32\bin”
  4. Run following lines
openssl genrsa -out privatekey.pem 1024
openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 365
openssl pkcs12 -export -out public_privatekey.pfx -inkey privatekey.pem -in publickey.cer

Copy .pem, .pfx & .cer files into solution for safe keeping. You will need to redo this prcess in 365 days as ssl will expire.

Install XeroAPI.Net into Visual Studio

Install using Package Manager Console – http://www.nuget.org/packages/XeroAPI.Net

Register your Application to Xero

  1. Go to https://api.xero.com/Application/Add
  2. Select public or private
  3. Give application name and upload .cer file
  4. Copy & Save Consumer Key

Write some code


  Protected Sub loadClientInvoices()

        Dim session As IOAuthSession = New XeroApi.OAuth.XeroApiPrivateSession("xxxx", "xxxxx", New X509Certificate2(Request.PhysicalApplicationPath + "\openssl\public_privatekey.pfx", "xxxx"))

        Dim repository As New Repository(session)

        Dim invoicesforClient As List(Of XeroApi.Model.Invoice) = (From x In repository.Invoices Where x.Contact.ContactID = New Guid("af5d6305-b5eb-441f-a5fb-8c9ea9c960ce")).ToList

        For Each invoice In invoicesforClient
            Response.Write(invoice.InvoiceNumber + "<BR>")

    End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: