Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

C# or VB.net Example

Started by David Bradley -   in Wrapper libraries

Hi Guys,

Can someone point me towards a working sample in either C# or VB.net whereby a Winforms application PUTS the minimal XML information and gets a response?

For someone who has never used json or API's before its all a bit confusing.

Hi David,

Are you using the C# SDK? (this one: https://developer.xero.com/documentation/libraries/using-the-xero-api-with-c)

You don't have to think about XML/json, all the endpoints are represented as classes so you just need to set their properties.



James Coleman (Community Manager)  

Hi James,

I am using VB. I had a look at the SDK and it's pretty difficult for me to make sense of.

For example, a simply example where an invoice was created similar to that created using Minimum XML block (https://app.xero.com/Preview/invoices/PUT) would be great.

But the sames don't seem to have anything like that, unless I'm missing something?




David Bradley  

Hi David,

I've put together a very simple example of using the C# SDK with Winforms, we don't have a VB.NET SDK yet so this isn't an option. Hopefully this will be helpful.


James Coleman (Community Manager)  

Hi James,
Can you show an example for using the C# SDK with Winforms for a public app? Thank you.

Tissl Development  

Hi James, same question as Tissi, can you show an example using the C# SDK for a public app? Would be a big help if you can, I'm struggling to get the app to connect with no call back uri - using oob, getting to the point where it gives the user the pin at the Xero site end, but then I can't find how to process that pin

Karen Gibbons  

James, I have also arrived at the same place of needing to send data to Xero accounts via dot net app. Despite being a VB.Net developer for many years, having a paid up Xero account, having created an app connection to the sample company and got the consumer key and consumer secret, done all the SSL cert stuff etc, studied the API wrapper, I just couldn't work out how to actually run a simple test eg. get a list of contacts. All the libraries appear to be DLLs that can't be run directly. I do know how to reference other DLLs etc. Ultimately, I need to code for sending sales invoices and credit notes and purchase invoices to a Xero company via a private app. OK, I have found your XeroWinForm c# example, added it to the project, made it the startup project and then ran. All compiled OK but soon gave the TLS1.0 error. It is was very unclear how to resolve this but I changed the dot net framework to 4.6 on all the projects. This then generated plenty of Nuget warnings about components installed for a different framework! Did an update on everything and still warning about NewtonSoft.Json but how do I know which dot net framework these components need anyway (can they be different, which framework should Xero.core be using?) Anyway, when I run I get an error in the Xero.Http.Client A validation exception occurred. Any ideas please? Thank you

Martin Sutherland  

Hi James

Will it be possible to give your example project above to work with the latest xero oauth please? I urgently need to be able to run the Xero api inside a windows service - no inputs, just to reuse the refresh token so my solution runs my integration with external system to create xero invoices.

So, the win forms example will help me.

Thank you in advance!

Jannie Blignaut  

Jannie, I am just working on doing exactly that, in vb.net. The way I did it was:

Watch this video: https://www.youtube.com/watch?v=Zcf_64yreVI&t=5s
Download and install XOauth, and generate your tokens
See how the access token and refresh token are sent to Xero with each get or post.

I suffered a lot with not really wanting to get my head around Async calls (or c#) so I'm using direct GET, PUT and POST calls, using the information in the end of that video to see what to put in the headers, and in the body, and how the responses work. I use the Xero models to build up the put and post body content, but the rest is just straight vb code. Virtually all the work I've had to do to convert my old OA1 code is to change it to call my http functions instead of using the api calls, and work on extracting error messages and so on from the responses.

I must say - I haven't yet done the conversion to a service, but I can't see any issues with it. My plan to deploy it will be to run XOAuth once, copy/paste the tokens and expiry time/date, client ID and tenant ID into the application settings, and go from there. That's what I do with the desktop version.

Unfortunately the code I've written is for a client so I can't post it, but it really isn't that tricky.


Mike Edwards  

Hi Jannie, Did you get it sorted? I just got my similar application running live. As Mike says, the code turns out to be quite basic if you ignore the SDK. I'm happy to share if it will help.

David Nye