0

I am writing some code in vb.net 2013 Express to access Xero accounting via a private application, and it's working fairly well. However I have come across a problem when trying to write some code to upload multiple contacts from a single XML file. I parse the XML, create a new contact from each line, and add it to a list of contacts. I then submit these to Xero:

try
   dim sResult = private_app_api.Create(mContacts)
Catch ex As Xero.Api.Infrastructure.Exceptions.ValidationException
 ' do something with ex to determine what went wrong
end try 

If all contacts create correctly, sresult contains a list of those contacts with their Xero-GUIDs, which I then need to feed back up to the system they are being sent from. This all works correctly.

If one or more of the contacts does not create for some reason, I get a list of one or more errors in the ex.ValidationErrors() collection, but I get nothing in sresult. So, I don't have a reference back to those that have worked, only those that have not.

To get around this, I am looping through each contact and pre-checking that they don't already exist on Xero, and don't have a duplicate name. This also works, and means that I only submit contacts that I know are not already on Xero.

My worry now, though, is that I am going to run into the Xero API limits of 60 calls in a rolling 60-second window. I am trying to make the code robust by pre-checking most of the common things that could cause a problem, but every time I do that, I get closer to the limit, which in theory means that I need to add some complexity by trying to throttle calls to Xero.

Is there a better way that I can call .create() and get both the successful information and the error information?

droopsnoot
  • 931
  • 1
  • 7
  • 11
  • Hey @droopsnoot - Myself and the Xero team have seen you helping in the forums countless times! I'd love to send you a thanks from the Xero community. Shoot me an email ( chris.knight@xero.com ) if your keen. – SerKnight Nov 20 '20 at 19:19

1 Answers1

0

I think the way around this seems to be to add a reference to RateLimiter when I first create the API object. This appears to implement a means where any calls that would exceed the rate limit are automatically paused. It seems necessary, though, to set the limit a little lower than 60 per 60-second rolling window, as I still get rate errors at that. I set it to 50, and my test code now waits a little while once it runs over the limit.

I haven't figured out how to implement both the 60/60s limit and the 5000/24h limit, though.

droopsnoot
  • 931
  • 1
  • 7
  • 11