Skip to content

Download Invoice ​

Returns a short-lived download link for an invoice PDF. Invoice IDs come from the invoices array of the Testimony Object — see Invoice Object.

HTTP Request ​

GET /api/v1/invoices/{invoiceId}/download

Response ​

200 OK

json
{
  "data": {
    "url": "https://storage.example.com/invoices/01J5X4C7D8E9F0G1H2J3K4L5M6.pdf?X-Amz-Expires=300&X-Amz-Signature=..."
  }
}

url is a presigned object-storage URL valid for 5 minutes — treat it as opaque and use it exactly as returned. That URL requires no authentication and serves the file with Content-Type: application/pdf and Content-Disposition: attachment; filename="{invoiceNumber}.pdf".

Frontend integration

The API request itself needs the Authorization: Bearer header, so a plain <a href> or window.open() pointing at the API URL fails with 401. Fetch the link first, then send the browser to it:

javascript
const response = await fetch(`/api/v1/invoices/${invoiceId}/download`, {
  headers: { Authorization: `Bearer ${accessToken}`, Accept: 'application/json' },
});

const { data } = await response.json();
window.location.assign(data.url); // the attachment disposition triggers a download

The presigned URL is self-authenticating — do not send the Authorization header to it. Request a fresh link for every download instead of storing one; it expires after 5 minutes.

Authentication ​

Requires authentication via Bearer token and a verified email. Only the invoice's supplier (the expert, for expert invoices) or its customer (the testimony's client) may download it (403 Forbidden otherwise).

401 Unauthorized

json
{
  "message": "Unauthenticated."
}

Error Handling ​

404 Not Found — the invoice PDF has not been rendered yet (hasPdf is false):

json
{
  "message": "Invoice file not found."
}

In production the message is the generic Not Found (see Error Responses). An unknown invoice ID answers 404 Not Found as well.

429 Too Many Requests — more than 120 requests per minute for this user.