Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Endpoints >

Batch upload of contacts and invoices via .NET wrapper

Started by Dale Shaw -   in API Endpoints


We are trying to cut down the number of hits via the API for uploading a batch of invoices ... maybe 350 in a single batch.

With 350 invoices we have issues with the per minute and per day limits.

So the suggestion was to send a batch via the .NET Wrapper and I am told it will accept multiple items to process via UpdateOrCreate methods. However, the programmer I have working on it tells me he can't see how. If we have code like that below he can't post it to the database.

Is there an example for batch uploads via C# wrapper?

Many thanks.


Contacts conts = new Contacts();

Contact con1 = new Contact();
con1.Name = "Contact1";

Contact con2 = new Contact();
con2.Name = "Contact2";


Hi Dale,

The XeroAPI.Net wrapper library can save batches of Invoices or Contacts in a single API call. The UpdateOrCreate method on the Repository class is overloaded to accept ICollection of TModel.

Contact contact1 = new Contact { Name="James" };
Contact contact2 = new Contact { Name="Jane" };
Contacts newContacts = new Contacts { contact1, contact2};
var processedContacts = repository.UpdateOrCreate(newContacts);

On a side note, you might want to test the size of batches of invoices or contacts that you're uploading to the Xero API. If the API has to process 350 invoices in a go, this may take over a minute - which could cause the client to timeout. I would suggest starting with batches of 10-20 and tune based on the observed performance.


Daniel Barratt (Xero Staff)  

Thanks Dan,

This is very helpful.

Yes, we were going to break our batch of 350 invoices into maybe 10 at a time. That will help avoid the limits and give the user some feedback etc.


Dale Shaw  


When our developed put your code in he gets:

The type 'XeroApi.Model.Contacts' cannot be used as type parameter 'TModel' in the generic type or method 'XeroApi.Repository.UpdateOrCreate<TModel>(TModel)'. There is no implicit reference conversion from 'XeroApi.Model.Contacts' to 'XeroApi.Model.ModelBase'.

As we missing something. We are used latest API wrapper so I can't see what may be wrong.


Dale Shaw  

Hi Dale.

Hmm.. it looks like IntelliSense gets confused between the overloaded methods. If you explicitly specify the generic type, then it'll work:



Daniel Barratt (Xero Staff)  


The guy dealing with it swears he tried that already but ... it worked 100% this time!

Thanks again.


Dale Shaw  

Hi Guys,

I'm trying to do exactly this but it won't work as the code won't compile?


Andrew Marks