benmccann/xero-java-client

Not sure how to create an invoice

Closed this issue · 1 comments

Hi

Could you give me a bit of help creating a invoice? I have written the following:

Reader pemReader = new FileReader(new File("privatekey.pem"));
XeroClient client = new XeroClient(pemReader,
        "xxxxx",
        "xxxx");

List<Contact> contacts = client.getContacts();
Invoice invoice = new Invoice();
LineItem item = new LineItem();
item.setDescription("hello");
invoice.getLineItems().add(item);
invoice.setType(InvoiceType.ACCREC);
invoice.setContact(contacts.get(0));
client.createInvoice(invoice);

But I get the error message

Exception in thread "main" com.connectifier.xeroclient.XeroApiException: 400 response: Error number 10. A validation exception occurred, One or more line items must be specified
    at com.connectifier.xeroclient.XeroClient.newApiException(XeroClient.java:103)
    at com.connectifier.xeroclient.XeroClient.put(XeroClient.java:135)
    at com.connectifier.xeroclient.XeroClient.createInvoice(XeroClient.java:310)
    at com.deepskybluesolutions.expenseimporter.ExpenseImporter.main(ExpenseImporter.java:31)

Can you advise what I am doing wrong?

I am hoping to use the xero-java-client to create Expense Claims. I guess I will need to expend xero-java-client to do this. Could you give me a few pointers on how to go about this?

thanks

Richard

Make sure you're using 0.13 and replace invoice.getLineItems().add(item); with invoice.setLineItems(ImmutableList.of(item));

I'm going to close this because I'm pretty sure that will fix your problem, but feel free to comment again if it doesn't.