Finance : Invoice download (PDF)
Omschrijving
Download een factuur als PDF-bestand. In tegenstelling tot de overige calls levert deze call geen JSON, maar direct de binaire inhoud van het PDF-bestand.
Endpoint
GET https://api.nextname.nl/v2/finance/invoices/{invoice_number}/download/{format}
Pad-parameters
| Parameter | Datatype | Verplicht | Omschrijving |
|---|---|---|---|
| invoice_number | String | Ja | Het factuurnummer van de te downloaden factuur (zoals teruggegeven door Invoices) |
| format | String | Ja | Het formaat van de opgevraagde factuur, momenteel alleen beschikbaar: pdf |
Antwoord
HTTP status code: 200 Ok
Het antwoord is geen JSON maar de binaire inhoud van het PDF-bestand. De response-headers zijn:
HTTP/1.1 200 OK Content-Type: application/pdf Content-Disposition: attachment; filename="2612345.pdf"
De body bevat de ruwe PDF-bytes. Schrijf die naar een bestand (of stream ze door naar de browser); parse het antwoord niet als JSON.
Voorbeeld
Beschrijving:
Download factuur 2612345 en sla het PDF-bestand lokaal op.
Opdracht in PHP:
<?php
$env = "live"; // live or test
$api_key = "XXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$invoice = "2612345";
$api_url = "/v2/finance/invoices/$invoice/download/pdf";
$api_host = $env === "live" ? "https://api.nextname.nl" : "https://api-test.nextname.nl";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_host . $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $api_key"));
$pdf = curl_exec($ch);
curl_close($ch);
// $pdf bevat de binaire PDF-inhoud; schrijf die naar een bestand.
file_put_contents("factuur-$invoice.pdf", $pdf);
Opdracht in cURL:
curl -H "Authorization: Bearer XXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \ -o factuur-2612345.pdf \ https://api-test.nextname.nl/v2/finance/invoices/2612345/download/pdf
Antwoord:
HTTP/1.1 200 OK Content-Type: application/pdf Content-Disposition: attachment; filename="2612345.pdf"
De binaire PDF-inhoud volgt in de body en wordt door het voorbeeld opgeslagen als factuur-2612345.pdf.