Justin Erswell Justin Erswell - 4 months ago 47
PHP Question

XERO PHP SDK - Get Invoice PDF

I am using the Xero PHP SDK (This one https://developer.xero.com/code-samples/libraries/php/) and I am able to post an invoice with no problems.

However, I am having issues understanding how I can retrieve the posted invoice's PDF, as I need to manually email this to the customer.

I believe the standard invoice request should be formatted thusly, but this will return all invoices.

$XeroOAuth->request('GET', $XeroOAuth->url('Invoices', 'core'), array());

My Question, therefore, is using the above SDK and call format how would I…

  1. Target a specific invoice by its ID

  2. Retrieve a PDF of the said invoice.

Some code examples would really help me out. Thanks!


To get the PDF output use the following

$response = $XeroOAuth->request('GET', $XeroOAuth->url('Invoice/'.$InvoiceID, 'core'), [], "", 'pdf');
if($XeroOAuth->response['code'] == 200){
  $myFile = $invoices->Invoices[0]->Invoice->InvoiceID.".pdf";
  file_put_contents($myFile, $XeroOAuth->response['response']);