0

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!

Justin Erswell
  • 688
  • 7
  • 42
  • 87

1 Answers1

2

To get the PDF output use the following

<?php
$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']);
}
Eddie
  • 195
  • 1
  • 3
  • 14