我设法添加了一个联系人但是当我尝试添加发票时,我收到一条错误消息'发生了验证异常'。我希望得到关于导致此错误的原因的建议。
private void button1_Click(object sender, EventArgs e)
{
try
{
/// first create an instance of the Xero API
var api = new Xero.Api.Example.Applications.Private.Core(false);
Contact newContact = new Contact();
newContact.Name = "Orac";
Invoice newInvoice = new Invoice();
newInvoice.Contact = new Contact();
newInvoice.Contact = newContact;
newInvoice.Date = System.DateTime.Now;
newInvoice.DueDate = System.DateTime.Now.AddMonths(1);
newInvoice.Status = Xero.Api.Core.Model.Status.InvoiceStatus.Authorised;
newInvoice.Type = Xero.Api.Core.Model.Types.InvoiceType.AccountsReceivable;
List<LineItem> lines = new List<LineItem>();
LineItem li = new LineItem();
li.LineAmount = Convert.ToDecimal("200.00");
li.Quantity = Convert.ToDecimal("1.0000");
li.ItemCode = "100";
li.Description = "Webdev inv test";
li.AccountCode = "200";
li.UnitAmount = Convert.ToDecimal("50.00");
lines.Add(li);
newInvoice.LineItems = lines;
// call the API to create the contact
api.Invoices.Create(newInvoice);
//api.Contacts.Create(newContact);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
答案 0 :(得分:2)
保留您的创作请求的结果 - 例如
var result = api.Invoices.Create(newInvoice);
...并检查结果的错误和警告属性,以确定您的请求有什么问题。
答案 1 :(得分:2)
抛出的异常类型是ValidationException。要么专门捕获该类型,要么强制转换捕获的通用异常,并检查ValidationErrors属性