Skip to content

Instantly share code, notes, and snippets.

@XeroAPI
Created September 22, 2011 06:27
Show Gist options
  • Save XeroAPI/1234181 to your computer and use it in GitHub Desktop.
Save XeroAPI/1234181 to your computer and use it in GitHub Desktop.
Sample code to show capturing a validation error in the XeroAPI.Net wrapper library
// Try and create an invoice - but using incorrect data. This should hopefully be rejected by the Xero API
Invoice invoiceToCreate = new Invoice
{
Contact = contact,
Type = "ACCREC",
Date = DateTime.Today,
LineItems = new LineItems
{
new LineItem
{
AccountCode = "200",
Description = "Blue Widget",
UnitAmount = 10m,
TaxAmount = 2m,
LineAmount = 12m
}
}
};
var createdInvoice = repository.Create(invoiceToCreate);
if (createdInvoice.ValidationStatus == ValidationStatus.ERROR)
{
foreach (var message in createdInvoice.ValidationErrors)
{
Console.WriteLine("Validation Error: " + message.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment