• This repository has been archived on 13/Apr/2021
  • Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    C#
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A skinny wrapper of the Xero API. Supports Payroll, Accounting & Files

Xero-Net

Looking for OAuth 2.0?

Please checkout Xero-NetStandard SDK for OAuth 2.0 and one of it's starter projects. Xero-NetStandard starter for .NET Core or Xero-NetStandard starter for .NET Framework 4.6.1 and higher

Xero-Net for OAuth 1.0a Deprecated as of April 2021

As of April 2021, Xero is deprecating support for OAuth 1.0a. If you need more time to complete your migration to OAuth 2, please contact [email protected] for assistance.

We are archiving this repository. For those wishing to use Xero-Net going forward you have the option of forking the Xero-Net repository. We recommend moving to Xero-NetStandard SDK for OAuth 2.0 as it will be supported and maintained going forward.

xero-api-sdk MyGet Build Status Build status

A skinny wrapper of the Xero API. Supports Payroll. All third party libraries are included as source code.

Installation

There are different way to install this library:

  1. Download the source code from github and compile yourself: https://github.com/XeroAPI/Xero-Net
  2. Download directly into Visual Studio using the NuGet powershell command PM> Install-Package Xero.API.SDK.Minimal to get a minimal installation.
  3. Download directly into Visual Studio using the NuGet powershell command: PM> Install-Package Xero.API.SDK to get a larger installation with sample token store using SQLite.

What is supported?

Core

  • Accounts - Create, Find and Update
  • Attachments - Add, Get and List
  • Bank Transactions - Create, Find and Update
  • Bank Transfers - Create and Find
  • Branding Themes - Find
  • Contacts - Create, Find and Update
  • Credit Notes - Create, Find and Update
  • Currencies - Find
  • Employees - Create, Find and Update
  • Expense Claims - Create, Find and Update
  • Invoices - Create, Find and Update
  • Items - Create, Find and Update
  • Journals - Find
  • Manual Journals - Create, Find and Update
  • Organisation - Find
  • Payments - Create, Find and Update
  • Purchase Orders - Create, Find and Update
  • Receipts - Create, Find and Update
  • Repeating Invoices - Find
  • Reports - Find
  • Setup - Create and Update
  • Tax Rates - Create, Find and Update
  • Tracked Inventory - Create and Update Tracked Inventory Items. Purchase, sell, and adjust inventory
  • Tracking Categories - Create, Find and Update. Add, Update and Remove TrackingOptions
  • Users - Find

Australian Payroll

  • Employees - Create and Find
  • Leave Applications - Create and Find
  • Pay Runs - Create and Find
  • Payroll Calendars- Create and Find
  • Pay Slips- Create and Find
  • Settings - Find
  • Super Fund Products - Find
  • Super Funds - Create and Find
  • Timesheets - Create and Find

United States Payroll

  • Employees - Create and Find
  • Pay Runs - Create and Find
  • Pay Schedules - Create and Find
  • Pay Stubs- Create and Find
  • Settings - Find
  • Timesheets - Create and Find
  • Work Locations - Create and Find

Files API

  • Files - Find, Add, Rename, Move, Remove and Get Content
  • Folders - Find, Add, Rename and Remove
  • Inbox - Find

Things to note

  • The library tries to do as little as possible and provides a basis to be extended. There are examples of TokenStores, Authenticators and Application types. These examples provide enough to get you going, but are not a complete solution to all your needs. You will need to adapt them for your own use and situation. Private application will work out of the box, as they do not have to deal with tokens and OAuth.
  • The HTTP verbs are not used in the public part of the API. Create, Update and Find are used instead. This separates the implementation from the intent.
  • Some accounting endpoints support pagination. In the RESTful API these are off by default. For the wrapper, they are always on and default to page 1. See the Counts or Creation code examples for how to use the Page method to get all items.
  • Contacts support including archived contacts. Like the RESTful API, this if off by default. Use IncludeArchived(true) to include them.
  • Payroll supports paging on all endpoints.
  • Four decimal places are supported and are always on.
  • You will need an instance of the API per organisation / connection. The connection is stored as part of the API instance.
  • Query parameters are cleared after each operation on an endpoint. If you use Invoices.Where("Type == "ACCREC"").Find() when querying invoices for example, the next Invoices.Find() will not retain the where clause query parameter.

Samples

There are samples for each of the API endpoints. These have been done as console application and also a collection of NUnit tests. See the README for each of the executable and test assemblies. The test projects contain lots of useful examples of how to use this library to interact with the Xero API.

Querying

There are simple filters on different endpoints.

  • ModifiedSince
  • Where
  • Or
  • And
  • OrderBy
  • OrderByDescending
  • Page
  • Offset

They are used in a Fluent way, but are not LINQ. They simply create a query for the URL passed to the API. Nested queries are not handled using the syntax. Or and And need to come after a Where statement. OrderBy, OrderByDescending and Page can come anywhere.

var invoices = xeroApi.Invoices  
	.ModifiedSince(new DateTime(2014, 1, 31))  
	.Where("Total > 3500.0")  
	.And("Total < 10000.0")  
	.Page(2)  
	.OrderByDescending("DueDate")  
	.Find();

The following gives the same query string to the API as the example above.

var invoices = xeroApi.Invoices  
	.Page(2)  
	.OrderByDescending("DueDate")  
	.Where("Total > 3500.0")   
	.And("Total < 10000.0")  
	.ModifiedSince(new DateTime(2014, 1, 31))  
	.Find();

Application types

There are specific classes for each of the application types. If these are used, you will need to have the app.config file settings for your organisation.

For a public application you would use

var user = new ApiUser { Name = "The users name" };
var tokenStore = new SqliteTokenStore();

var api = new Applications.Public.Core(tokenStore, user)
{
    UserAgent = "Something to show your application"
};

The config file will look like this

<add key="BaseUrl" value="https://api.xero.com"/>
<add key="ConsumerKey" value="Your Key"/>
<add key="ConsumerSecret" value="Your secret"/>
<add key="CallbackUrl" value="Your callback"/>

There are classes for Private, Public and Partner applications for the Core Xero API and Australian and American Payrolls.

A private application will need to also populate

<add key="SigningCertificate" value="Path to .pfx file"/>

A partner application will need to also populate

<add key="SigningCertificate" value="Path to .pfx file"/>

Authenticators

The application classes all use implementations of IAuthenticator. See PrivateAuthenticator for an example. The authenticators are used by the base infrastructure to do the heavy lifting of the Xero API authentication.

PrivateAuthenticator

Uses RSA-SHA1 and a public/private certificate. There are no tokens and each request has to be signed.

PublicAuthenticator

Uses HMAC-SHA1 and the standard 3-legged OAuth process. Tokens last for 30 minutes and cannot be renewed.

PartnerAuthenticator

Uses RSA-SHA1 and then the standard 3-legged OAuth process with an additional signing certificate. Tokens last for 30 minutes and be renewed. Token renewal is supported by this provider.

Examples for renewing your access tokens can be seen in the RenewToken method overrides in the PartnerAuthenticator.cs and PartnerMVCAuthenticator.cs classes.

OAuth signing

All the signing is done by a slightly modified version of the Dust library provided by Ben Biddington. Source is included.

Token Stores

The token store implementations are separate and optional. (It is recommended that you do have a store.)

The interface ITokenStore has three methods.

public interface ITokenStore
{
	IConsumer Find(string user);
	void Add(IToken token);
	void Delete(IToken token);
}

You can provide your own implementation to suit the database you are using for your product. Ensure the dates on the token are stored in UTC.

The examples are

  • MemoryTokenStore - Dictionary of token in RAM keyed on UserId
  • SqliteTokenStore - A database of tokens (file on local disk). This does not support multiple add-ons in the same database. The tokens are only for the application the database was created by.

Serialization

All communication with the Xero API is compressed at source. Writing to the API is done with XML. The data model classes have be attributed to give a small XML payload. All communication back from the API is JSON. These details are transparent to the user of the class library.

Usage

To get going quickly:

  1. Follow this getting started guide: http://developer.xero.com/documentation/getting-started/getting-started-guide/
  2. Create a console project and download the following package using the NuGet powershell command: PM> Install-Package Xero.API.SDK
  3. Use the snippets below depending on the type of application, modifying keys and certificate paths.

Note, remember to implement your own custom token store before going live. The examples provided in the library Xero.Api.Example.TokenStores.dll are for development only.

static void Main(string[] args)
{
	// Private Application Sample
	var private_app_api = new XeroCoreApi("https://api.xero.com", new PrivateAuthenticator(@"C:\Dev\your_public_privatekey.pfx"),
        new Consumer("your-consumer-key", "your-consumer-secret"), null,
        new DefaultMapper(), new DefaultMapper());

	var org = private_app_api.Organisation;

	var user = new ApiUser { Name = Environment.MachineName };

	// Public Application Sample
    var public_app_api = new XeroCoreApi("https://api.xero.com", new PublicAuthenticator("https://api.xero.com", "https://api.xero.com", "oob",
		new MemoryTokenStore()),
        new Consumer("your-consumer-key", "your-consumer-secret"), user,
        new DefaultMapper(), new DefaultMapper());

    var public_contacts = public_app_api.Contacts.Find().ToList();

	// Partner Application Sample
	var partner_app_api = new XeroCoreApi("https://api-partner.network.xero.com", new PartnerAuthenticator("https://api-partner.network.xero.com",
        "https://api.xero.com", "oob", new MemoryTokenStore(),
        @"C:\Dev\your_public_privatekey.pfx"),
         new Consumer("your-consumer-key", "your-consumer-secret"), user,
         new DefaultMapper(), new DefaultMapper());

	var partner_contacts = partner_app_api.Contacts.Find().ToList();			
}

Acknowledgements

Thanks for the following Open Source libraries for making the wrapper and samples easier

License

This software is published under the MIT License.

Copyright (c) 2016 Xero Limited

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

xero-node

Xero Node SDK for OAuth 2.0 generated from XeroAPI/Xero-OpenAPI
TypeScript
194
star
2

XeroOAuth-PHP

PHP class for the Xero API V2
PHP
123
star
3

xero-python

Official Xero OAuth 2.0 python SDK
Python
122
star
4

Xero-NetStandard

A wrapper of the Xero API in the .NetStandard 2.0 framework. Supports Accounting, Payroll AU/US, and Files
C#
121
star
5

Xero-OpenAPI

An OpenAPI description of the Xero API
Mustache
94
star
6

xero-php-oauth2

Xero PHP SDK for oAuth 2 generated from Xero API OpenAPI Spec 3.0
PHP
90
star
7

Xero-Java

Official Java client for use with Xero API
Java
74
star
8

xero-ruby

Xero Ruby SDK for OAuth 2.0 generated from XeroAPI/Xero-OpenAPI
Ruby
57
star
9

xoauth

A CLI tool for obtaining JWTs from OpenId Connect providers
Go
49
star
10

XeroAPI.Net

(previous SDK version - no longer supported)
C#
47
star
11

xero-node-oauth2-app

NodeJS app for demonstrating the xero-node v4 SDK
TypeScript
35
star
12

xero-python-oauth2-starter

Python
29
star
13

xero-postman-oauth2

A postman collection for use with Xero's API and OAuth 2.0
24
star
14

xerogolang

Golang SDK for the Xero API
Go
24
star
15

xero-php-oauth2-app

PHP app for demonstrating the xero-php-oauth2 SDK
PHP
22
star
16

xero-php-oauth2-starter

This is a starter app with the code to perform OAuth 2.0 authentication
PHP
16
star
17

xero-python-oauth2-app

python app for demonstrating the xero-python SDK
Python
16
star
18

XeroWebhooksReceiver

An example .Net Core application for receiving webhooks from Xero
C#
15
star
19

xero-netstandard-oauth2-starter-dotnet-core

This is a starter app build with .NET Core 3.1 MVC to demonstrate Xero OAuth 2.0 Client Authentication & OAuth 2.0 APIs.
C#
14
star
20

Xero-Postman

A Postman collection for authenticating to the Xero API
13
star
21

xero-ruby-oauth2-app

Ruby on rails app for demonstrating the xero-ruby SDK
Ruby
12
star
22

Xero-Insomnia

Insomnia collection for the [XeroAPI](https://developer.xero.com/documentation/) - plug in your API app params to start exploring
11
star
23

xero-netstandard-oauth2-samples

Contains sample implementations making use of Xero Sign In and Outh2
C#
10
star
24

golang-oauth2-example

A basic example using golang to complete the OAuth 2 flow on Xero's API without the use of an SDK.
Go
9
star
25

xero-netstandard-oauth2-app

The companion app for Xero .NET SDK
C#
8
star
26

node-oauth2-example

A short and simple example using node and express with openid-client to complete the OAuth flow on Xero's OAuth 2 API without the use of an SDK.
JavaScript
8
star
27

Xero-NetStandard-Webhooks-Receiver

C#
7
star
28

xero-node-oauth2-ts-starter

Starter typescript code for use with xero-node v4
TypeScript
7
star
29

xero-java-oauth2-app

Java app for demonstrating the Xero-Java SDK
Java
6
star
30

xero-oauth2-omniauth-strategy

An Omniauth strategy created for Xero API OAuth 2 based on the generic Omniauth OAuth 2 strategy.
Ruby
6
star
31

xero-node-oauth2-react-app

JavaScript
6
star
32

Api.Documentation

Documentation for Xero's public API
6
star
33

xero-netstandard-oauth2-starter-app-dotnet-framework

This is a starter app build with .NET Framework v4.6.1 MVC to demonstrate Xero OAuth 2.0 Client Authentication & OAuth 2.0 APIs.
JavaScript
6
star
34

net-desktop-pkce-example

.NET OAuth 2.0 example using PKCE to interact with the XeroAPI
C#
4
star
35

xero-oauth2-omniauth-sample

A Ruby on Rails sample application to demonstrate the usage of xero-oauth2-omniauth ruby gem.
Ruby
4
star
36

xero-node-sso-app

Showing an example Single Sign On / "Sign up with Xero" Flow using xero-node SDK
EJS
3
star
37

xero-ruby-oauth2-starter

This is a starter app to perform OAuth 2.0 authentication with xero-ruby
Ruby
3
star
38

xero-ruby-sso-form

An example of the "Sign up with Xero to Lead" flow using the Ruby SDK. The authentication results in a pre-populated sign up form.
Haml
3
star
39

xero-php-webhook

PHP example of code for verifying and receiving a Xero webhook
PHP
3
star
40

Xero-Postman-Tutorial-PKCE-Edition

3
star
41

xero-php-oauth2-custom-connections-starter

Starter app showing Xero's Custom Connections functionality aka OA2 grant_type: `client_credentials`
PHP
3
star
42

xero-java-oauth2-starter

Java starter code for use with Xero-Java SDK to complete OAuth 2 flow
Java
2
star
43

xeropracticemanager-dotnetcore-oauth2-sample

Contains sample implementations making use of the Xero Practice Manager v3 API and OAuth2
C#
2
star
44

xero-ruby-token-migration-script

Ruby script for migrating OAuth1.0a tokens to OAuth2.0
Ruby
2
star
45

workflowmax-postman-oauth2

A postman collection for use with WorkflowMax's API and OAuth 2.0
2
star
46

php-oauth2-example

A PHP example of the OAuth 2.0 flow and Xero's API without the use of an SDK
PHP
2
star
47

xero-netstandard-oauth2-blazor-pkce

Sample application showing a basic Files Api integration using Blazor WebAssembly.
C#
2
star
48

xero-ruby-custom-connections-starter

Simple starter repo showing how to integrate with Xero
Ruby
1
star
49

workflowmax-dotnetcore-oauth2-sample

Contains sample implementations making use of the WorkflowMax v3 API and OAuth2
C#
1
star
50

xero-landing-page

A landing page template to help app partners market their new integration in Xero's marketplace
1
star
51

xero-net-oauth2-sampletokenmigration

Sample app for migrating OAuth1.0a tokens to OAuth2.0 tokens.
C#
1
star
52

Xero-Net-Sign-Up-With-Xero-Samples

C#
1
star
53

Xero-NetStandard-custom-connections-starter

Starter app showing Xero's Custom Connections functionality aka OA2 grant_type: `client_credentials`
C#
1
star
54

xero-python-custom-connections-starter

Custom Connections starter app for xero-python and client_credentials grant
Python
1
star