I have checked documents and tried various combinations (to the best of my ability) I am attempting to create an invoice in Xero using PHP. I found this answer the closet I've got to completing the task:
xero PHP variable which starts with {
However I am still unable to pass data correctly (resulting in a 400 error: "ErrorNumber": 17, "Type": "NoDataProcessedException", "Message": "No data has been processed for this endpoi (truncated...)"):
$invoices = '{"invoices":[{"type":"Invoice.TypeEnum.ACCREC","contact":{"contactID":"00000000-0000-0000-000-000000000000"},"lineItems":[{"description":"Acme Tires","quantity":2,"unitAmount":20,"accountCode":"000","taxType":"NONE","lineAmount":40}],"date":"2019-03-11","dueDate":"2018-12-10","reference":"Website Design","status":"Invoice.StatusEnum.DRAFT"}]}';
$invoices = json_encode($invoices);
$summarize_errors = true; // bool | If false return 200 OK and mix of successfully created objects and any with validation errors
$unitdp = 4; // int | e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal places for unit amounts
try {
$result = $apiInstance->createInvoices($xeroTenantId, $invoices, TRUE, 4);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AccountingApi->createInvoices: ', $e->getMessage(), PHP_EOL;
}
I have also attempted (resulting in a 500 error: "Title":"An error occurred","Detail":"An error occurred in Xero. Check the API Status page http://status.developer.xero (truncated...)"):
$result = $apiInstance->getContacts($xeroTenantId);
$contactId = $result->getContacts()[0]->getContactId();
$contact = new XeroAPI\XeroPHP\Models\Accounting\Contact;
$contact->setContactId($contactId);
$arr_invoices = [];
$lineitems = "TEST";
$invoice_1 = new XeroAPI\XeroPHP\Models\Accounting\Invoice;
$invoice_1->setReference('Ref-456')
->setDueDate(new DateTime('2019-12-10'))
->setContact($contact)
->setLineItems($lineitems)
->setStatus(XeroAPI\XeroPHP\Models\Accounting\Invoice::STATUS_AUTHORISED)
->setType(XeroAPI\XeroPHP\Models\Accounting\Invoice::TYPE_ACCREC)
->setLineAmountTypes(\XeroAPI\XeroPHP\Models\Accounting\LineAmountTypes::EXCLUSIVE);
array_push($arr_invoices, $invoice_1);
$invoices = new XeroAPI\XeroPHP\Models\Accounting\Invoices;
$invoices->setInvoices($arr_invoices);
try {
$result = $apiInstance->createInvoices($xeroTenantId,$invoices, TRUE , 4);
print_r($result);
} catch (Exception $e) {
echo 'Error : ', $e->getMessage(), PHP_EOL;
}
If anyone can shine light or provide an update to either snippet I would be extremely grateful, thank you.