Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Wrapper libraries >

php-Xero Wrapper Return XML

Started by Peter Kaye(GM) -   in Wrapper libraries

Why does...
<pre>
$xero = new Xero(XERO_KEY, XERO_SECRET, 'publickey.cer', 'privatekey.pem', 'xml' );
echo $result->asXML();
</pre>
.. not return xml ?

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


Kind Regards
Henzard Kruger
Certified Advisor and API developer
Picahoo cc - 0711304241 - henzard@picahoo.co.za
Skype: henzard, Gtalk: henzardkruger@gmail.com
 

Henzard Kruger  

Thanks Henzard. This code relates to the XeroOAuth-php library whereas the question actually related to the older php-Xero library which is the library I have used in the past. However I'm keen I move with the times and migrate to this newer library.

As far as I can see the code you post is exactly the same as private.php in the code samples posted in the XeroOAuth-php library. And I'm already using this in conjuction with tests.php and all I can get back is JSON. I'd be really appreciative if you could post some sample code which retrieved all accounts or contacts as xml.

Thanks again for your help for far on this.
 

Peter Kaye(GM)  

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


Notice the $accounts->Accounts it's simplexml class build into php. You could now $accounts->Accounts->asXML() for string object.
 

Henzard Kruger  

Thanks again Henzard - but I'm still struggling with this.
How does this function you have kindly provided fit in with my attempts to use the test code in the XeroOAuth-php library test code ?
And I'm puzzled by the function title addAccounts = I don't want to add anything at this stage, just bring back data. So the PUT also seems strange.
And what object does $Account represent ? And where do I find information on the token property ?

Sorry if these questions show ignorance but I can find very little documentation on this wrapper library other than the test code.

I have in place the earlier code that you posted which works as per the library test frame - what I need now is to see what I need to change in the part of tests.php which will bring back the perfect list of accounts that I get in json format instead as xml.

I hope you can bear with me the extra mile on this. Feel free to point me to some API documentation if you think that might help.

(P.S I'd post some code but there are some rules in this forum that I don't understand which limits code - maybe I need to go the github route as you have done if what I am asking is still unclear).

 

Peter Kaye(GM)  

Your return is object not JSON. JSON and XML is text encodings to describe the data that comes back what you have in tests.php is a object. Just Foreach it.
 

Henzard Kruger  

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


I rewrote the wrapper to support OOP.

Maybe we need to continue this on skype.
 

Henzard Kruger  

foreach ($accounts->Account as $acc) {
echo "<tr><td>$acc->Name</td><td>$acc->Code</td></tr>";
}
 

Henzard Kruger  

Thanks Henzard but I've obviously implemented your code incorrectly as it fails to compile. (Fatal error: Using $this when not in object context in /home/sites/marionandpeter.com/public_html/xeronphp/privaten4c.php on line 71)
This code is provided by the developer community - Xero does not warrant it in any way

Here's some background to this work . As this shows I can get JSON back ok.
I hope if you can correct the gist code then I may get to understand what's going on !
Thanks again.
 

Peter Kaye(GM)  

Let's setup a skype meeting.
 

Henzard Kruger