Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

Visual Studio C# winforms Nuget .NET wrapper API find contact

Started by John Bassett -   in Wrapper libraries

I am new to Xero and new to the API. I am developing an interface into Xero for a client and have managed to add new contacts and invoices but am struggling to find out how to do what should be really standard and basic things like check whether contact exists before adding a new contact and editing fields for existing contacts. Finding information on how to do even really basic things is ridiculously time-consuming and difficult and it does not seem to be all in one place. I am using Visual Studio C# winforms and have installed the Nuget wrapper. Googling, downloading the Github sample code etc, forums provides lots of long-winded, complicated possible solutions but there should surely be a short-cut to all this. Currently I have managed a workaround by loading all the contacts into a list (where the 100 per 'page' limit came from I can't begin to imagine) and checking against the list. Even the installation and set-up I did not get from Xero but some really helpful third-party web-site. I am sure I will figure it all out eventually but the project size and revenue does not merit the time it is taking so far and it really should not be necessary. Where can I get information on sample code to do these basic things in C# using the wrapper for example

1. Check if contact exists by Name or AccountNumber
2. Edit existing contact, for example to add AccountNumber
3. Delete contact (archive)
4. Similar for Invoices

Also I created a paid Xero account for development and need to transfer the keys to access my client's account. Is this possible if not how would I go about this ?

If this is not the right place to get support or answers to the above please indicate where is.

Thanks,

John
Hi John,

Did you try using Xero SDK (C#) which is provided by Xero for API access?

https://developer.xero.com/documentation/libraries/using-the-xero-api-with-c

Let us know if still not able to move ahead. .

Regards,
Zanesoft IT Solutions
info@zanesoft.com
 

Zanesoft IT Solutions  

Hi,

Thanks for your reply. Yes, I am using it.

I have not resolved it yet but I have made some progress using LINQ. I tried to post the code but the forum would not accept the post with the code.
 

John Bassett  

I have managed to achieve what I needed to do so far even if it probably is not in the ideal way. Contacts are being added and edited and invoices added. Doing it is fairly easy, finding how to do it was fairly time-consuming.
 

John Bassett  

Hi John
Would you mind sharing how you did this?
I can't find any documentation on using the API with WinForms! :/
Thank you
 

Jamie Lakes  

Hi Jamie,

Sorry for the delay in replying, I had to put the Xero project aside for a while as it was taking too much time and there were some higher priority projects that I needed to focus on. I am now getting back into it and trying to figure out what I did. I expect you have worked out how to use the API with WinForms but if not and you would still like me to share the little I know, please let me know.

John
 

John Bassett  

Hi John

Thanks for replying - I too had put the Xero project to the side for a bit. I managed to figure out one part of the API to show me the data in a table that I wanted. I'm happy to share my code if it benefits others. Perhaps if I could see yours then we might be able to put 2 and 2 together!
 

Jamie Lakes  

Hi,

I am ok with sharing my Xero api code although it is fairly messy. When I tried to include code in a post the post was rejected so I am not sure how you would like me to get the code to you.
 

John Bassett  

Hi John

That's great! Thank you...! You can post code on GitHub (https://gist.github.com) and then generate a URL to post in here.
 

Jamie Lakes  

Here's my messy but working code... It's not great but I eventually got it to pull down the invoices into a data table...

https://gist.github.com/J44LKS/d9054aba7e716b877a102d44a7ade590
 

Jamie Lakes  

My code is even messier but also works. It is code to update contacts and invoices. There is a fair amount of redundant code but I have not had a chance to comment it out or delete it yet.

https://gist.github.com/johndevelopersa/907866d162900b09d2829b085039bf94
 

John Bassett  

Hi John - thanks for this. Just an FYI, you've left your API key and secret in the source. I don't think it does anything without the certificate, but just thought I'd let you know.
 

Jamie Lakes  

Hi Jamie,

Thanks for letting me know. I have deleted the gist and added the amended code. Bit unfortunate but hopefully no harm done.
 

John Bassett  

Hi Jamie,

I expect you are aware of this but I think your code will only retrieve a maximum of 100 records as Xero only retrieves a 'Page' at a time and each page is a maximum of 100 rows. Strange but true !
 

John Bassett  

Hi John - yes I did read this somewhere, but I also read that the API supports pagination. It's just figuring out how that works!
 

Jamie Lakes  

Hi Jamie,

I use the pageination functionality in my code. If you need assistance, please let me know
 

John Bassett  

Hi John (or Jamie). I too am struggling with Xero API in vb.net. I was "excited" to see a link to your code which updates contacts but disappointed to see the web page has been removed. I suspect due to sensitive key details. I can create Accounts and Contactes and Invoices but do not know how to perform an "update".

I do an Add Account with...
xAccount = New Model.Account
xAccount.Name = NominalCodeDescription$
xAccount.Code = NominalCodeCode$
xAccount.Type = "SALES"
xAccount.TaxType = "NONE"
xAccount.Description = "Income from " & NominalCodeDescription$

Dim xResults = Repository.Create(xAccount)

but how on earh do I do an Update Account ?? I would be enormously grateful if you would share a bit of code to help me on my way.

Regards, Andy Hilbig
 

Andrew Hilbig  

Hi Andy,

I have not looked at this for a while and the code if fairly messy. I am not sure if it will
assist you but the link seems to be working now.

https://gist.github.com/johndevelopersa/938cf721e07ead43b63182baa9d3808d

If you would like further assistance let me know.

Regards,

John
 

John Bassett