# Download invoice PDF Download an invoice as a PDF file. Non-staff users can only download their organization's invoices. #### Path Parameters **`invoice_id`** string required Invoice ID (format: `inv_`). ## Returns Returns a PDF file with the invoice. The response includes: - **Content-Type**: `application/pdf` - **Content-Disposition**: `attachment; filename="INV-2024-12-AIT-001.pdf"` - **Body**: Binary PDF data ```bash curl "https://api.aitronos.com/v1/invoices/inv_123e4567e89b12d3a456426614174000/pdf" \ -H "X-API-Key: $FREDDY_API_KEY" \ -o invoice.pdf ``` ```python import os import requests api_key = os.environ["FREDDY_API_KEY"] invoice_id = "inv_123e4567e89b12d3a456426614174000" response = requests.get( f"https://api.aitronos.com/v1/invoices/{invoice_id}/pdf", headers={"X-API-Key": api_key} ) # Save PDF to file with open("invoice.pdf", "wb") as f: f.write(response.content) print("Invoice PDF downloaded successfully") ``` ```javascript const invoiceId = "inv_123e4567e89b12d3a456426614174000"; const response = await fetch( `https://api.aitronos.com/v1/invoices/${invoiceId}/pdf`, { headers: { "X-API-Key": process.env.FREDDY_API_KEY } } ); const blob = await response.blob(); const buffer = Buffer.from(await blob.arrayBuffer()); // Save to file (Node.js) const fs = require('fs'); fs.writeFileSync('invoice.pdf', buffer); console.log("Invoice PDF downloaded successfully"); ``` **Response:** 200 OK Binary PDF file with headers: ``` Content-Type: application/pdf Content-Disposition: attachment; filename="INV-2024-12-AIT-001.pdf" ``` 401 Unauthorized ```json { "success": false, "error": { "code": "AUTHENTICATION_REQUIRED", "message": "Authentication required", "system_message": "Missing or invalid authentication token", "type": "client_error", "status": 401, "details": {}, "trace_id": "2fbbf3b6-51a1-4f1b-88e2-c00e8b52fbb8", "timestamp": "2025-11-26T08:21:45Z" } } ``` 403 Forbidden ```json { "success": false, "error": { "code": "ORGANIZATION_ACCESS_DENIED", "message": "You don't have permission to access this invoice", "system_message": "User cannot access this organization's invoices", "type": "client_error", "status": 403, "details": { "invoice_id": "inv_123e4567e89b12d3a456426614174000" }, "trace_id": "2fbbf3b6-51a1-4f1b-88e2-c00e8b52fbb8", "timestamp": "2025-11-26T08:21:45Z" } } ``` 404 Not Found ```json { "success": false, "error": { "code": "INVOICE_NOT_FOUND", "message": "Invoice not found", "system_message": "Invoice does not exist", "type": "client_error", "status": 404, "details": { "invoice_id": "inv_123e4567e89b12d3a456426614174000" }, "trace_id": "2fbbf3b6-51a1-4f1b-88e2-c00e8b52fbb8", "timestamp": "2025-11-26T08:21:45Z" } } ``` 500 Internal Server Error ```json { "success": false, "error": { "code": "INTERNAL_ERROR", "message": "PDF generation failed", "system_message": "Error generating PDF document", "type": "server_error", "status": 500, "details": {}, "trace_id": "2fbbf3b6-51a1-4f1b-88e2-c00e8b52fbb8", "timestamp": "2025-11-26T08:21:45Z" } } ```