-3

I would like to use the invoiz api to download an invoice: https://app.invoiz.de/api/documentation/#/invoices/download%20InvoiceDocument

my code:

// DOWNLOAD INVOICES
$curl = curl_init('https://app.invoiz.de/api/invoice/ID_OF_INVOICE/download');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_USERPWD, $apiKey . ":" . $secretApiKey); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer '.$token->token,
    'accept: application/pdf'
));

$content = curl_exec($curl);
curl_close($curl);

echo $content shows:

enter image description here

But I would like to download the pdf file. How can I realize it?

CURL response:

access-control-allow-origin: *  
connection: keep-alive  
content-disposition: attachment; filename="MyFileName.pdf"  content-type: application/pdf  
date: Tue,31 Jan 2023 10:50:24 GMT  
strict-transport-security: max-age=7776000; includeSubDomains; preload  
transfer-encoding: chunked 
Trombone0904
  • 4,132
  • 8
  • 51
  • 104

1 Answers1

-4

You must put the header to pdf so that your browser understands that it is a pdf.

header('Content-Type: application/pdf');

Or to force download something like that :

header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file) . "\"");
Oz V
  • 1
  • 3
  • 2
    kindly, don't add duplicate answers. – OMi Shah Jan 31 '23 at 10:43
  • the first example works, but it will only show the file in browser (logically). with your second answer it should be automatically download the file. but where I get the $file? Please look in the response, which I get from the curl (my first post) – Trombone0904 Jan 31 '23 at 10:50