Invoice PDF download via REST API

m8code
New Community Member

I'm making POC for my client. I need to download batch of invoices in PDF format(for example, all invoices from last month). Is it possible to download pdf files via REST API? When I crawled on site I noticed request(aftek click PDF button in invoice actions) like this:
https://www.sandbox.paypal.com/invoice/actions/render-pdf/INV2-3DM5-KT37-4G3G-NU9T?time=161084669850...
Can I make that request from server side?

Login to Me Too
2 REPLIES 2

Hammer-Schlagen
New Community Member

@m8code --

 

Your link requires the viewer to be logged-in to their account, and will only display the invoice if the logged-in user is a party to the invoice.  There is a not-so-well-know URI that took me several months to figure out.  In demonstration, here's a PHP function that cURL's the PDF's bytes of a specific invoice so they can be later saved as appropriate:

 

 

Spoiler

function get_invoice_bytes($paypal_id) {

   $ch = curl_init();

   curl_setopt_array($ch, array(
      CURLOPT_URL => 'https://www.sandbox.paypal.com/invoice/payerView/detailsInternal/' . $paypal_id .'?printPdfMode=true ',
      CURLOPT_FOLLOWLOCATION => TRUE,
      CURLOPT_HEADER => FALSE,
      CURLOPT_RETURNTRANSFER => TRUE,
    ));
    $bytes = curl_exec($ch);
    curl_close($ch);
    return $bytes;

}

$pdf_bytes = get_invoice_bytes('INV2-3DM5-KT37-4G3G-NU9T');

 

Login to Me Too

agruhn
Contributor
Contributor

i have write a little php script which downloads invoice details and renders the links to download as html page. then u can open it into browser and open all links in tabs at once for multi download.

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.