Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Endpoints >

php create invoice issue

Started by Yogi Bear -   in API Endpoints


I am trying to use PHP to create invoices in xero.
So far I've got the following code which is using data obtained from another database. The invoice adds fine, however it will only add one line item. I need to be able to add additional line items to the array at a later stage, but i'm not too good with multi dimensional arrays.

Can someone advise how, once I have run the below code, I would add just an additional line item to this record in the array so when I add it into xero it will contain multiple line items.


$new_invoice = array(
"Contact" => array(
"ContactNumber" => "$customerid"
"InvoiceNumber" => "$sageinvid",
"Date" => "$invoicedate",
"DueDate" => "$duedate",
"Status" => "SUBMITTED",
"LineAmountTypes" => "Exclusive",
"LineItems"=> array(
"LineItem" => array(
"Description" => "$product",
"Quantity" => "$qty",
"UnitAmount" => "$amtnett",
"AccountCode" => "200"

$invoice_result = $xero->Invoices( $new_invoice );
Hi Boo Boo Bear,

You just need to replicate the LineItem array. Try this:

This code is provided by the developer community - Xero does not warrant it in any way


W. Abdullah (Community Manager)  

I am trying to create a account in xero using php script. i am giving below codes but account is not creating , please help me :-
$new = array(
"Code" => "413",
"Name" => "Consulting & Accounting12"
"Status" => "ACTIVE",
"Type" => "EXPENSE",
"TaxType" => "NONE",
"Description" => "Expenses related to paying consultants"
"Class" => "EXPENSE",
"EnablePaymentsToAccount" => false,
"ShowInExpenseClaims" => true
$result = $xero->Accounts($new);
Thanks in advance !!!

swapna patro  

Hi there,
Unfortunately it is not possible to add/create account via API at the moment.

Please have a look at the Accounts endpoint reference - http://blog.xero.com/developer/api/Accounts/

We have a feature request for it on our Uservoice site. If you added your vote, you'll be notified when there's changes on its status.

W. Abdullah (Community Manager)  

Thanks a lot For your response.
I have another question, can we add/create "Tax Rate" via API ?
For tax rate i am using below code, but not able to add. Please help me
$tax_rate = array(
"Name" => "Zero Rated",
"TaxType" => "ZERORATED",
"CanApplyToAssets" => false,
"CanApplyToEquity" => false,
"CanApplyToExpenses" => false,
"CanApplyToLiabilities" => false,
"CanApplyToRevenue" => true ,
"DisplayTaxRate" => "0.0000",
"EffectiveRate" => "0.0000"
$result = $xero->TaxRates($tax_rate);
Thanks in advance !!!

swapna patro  

TaxRates endpoint only support GET method at this time.

Please read our API Reference documentation thoroughly at http://blog.xero.com/developer/api/

W. Abdullah (Community Manager)  

Thanks for Help,
I was using xero trial api which had valid period for 28 days. Now my keys got expired.So again i created new cretification files and generated keys.By using those keys i am getting error
"Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found in F:\wamp\www\Xero\xero.php on line 311

Warning: simplexml_load_string() [function.simplexml-load-string]: oauth_problem=token_rejected&oauth_problem_advice=The%20organisation%20for%20thi in F:\wamp\www\Xero\xero.php on line 311

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in F:\wamp\www\Xero\xero.php on line 311
in case of any suggestion please let me know.
Thanks in advance!!!

swapna silu  


You received the error because the Xero company that you connect your application with, has been deleted.

The solution is to create a new Private application and connect it to an existing Xero company.

W. Abdullah (Community Manager)  

I have implemented the $new_invoice array and while submitting I am getting the error "Error: 17 NoDataProcessedException No data has been processed for this endpoint. This endpoint is expecting Invoice data to be specifed in the request body. "

Anjan Khatua