Download invoices
When working with invoices, it is important to differentiate between:
- Legal invoice file: the final official file that was delivered (issued invoices) or received (received invoices).
- Original invoice file: the first file received by B2Brouter for that invoice (for issued invoices, this is typically an imported source file; for received invoices, this is the invoice received from the issuer).
- Exporting an invoice to a specific format: B2Brouter generates a document from the invoice data (it may differ from the legal/original file).
- Attachments: additional files linked to the invoice (PDFs, etc.). Attachments are not the invoice itself.
Depending on what you need, you will either:
- Call a direct download endpoint (for example,
/invoices/{INVOICE_ID}/as/original), or - Use a download path returned in the invoice JSON (for example,
download_legal_urlorattachments[].link).
Prerequisites
Section titled “Prerequisites”- An API key with access to the invoice’s project/account.
- The internal B2Brouter
invoice.id(you can obtain it from list endpoints).
Step 1: Get the invoice payload (optional but recommended)
Section titled “Step 1: Get the invoice payload (optional but recommended)”Call Get invoice to retrieve the invoice JSON and locate the relevant fields:
curl --request GET \ --url https://api-staging.b2brouter.net/invoices/{INVOICE_ID}.json \ --header 'X-B2B-API-Key: {YOUR_API_KEY}' \ --header 'X-B2B-API-Version: {YOUR_API_VERSION}' \ --header 'accept: application/json'Issued invoices: legal file via download_legal_url (IssuedInvoice / IssuedSelfInvoice)
Section titled “Issued invoices: legal file via download_legal_url (IssuedInvoice / IssuedSelfInvoice)”After an issued invoice is sent, the response can include download_legal_url, which points to the legal file delivered to the receiver (for example, the exact XML submitted to a network/platform, or the legal PDF).
download_legal_url is a relative path (not a full URL), for example:
{ "invoice": { "download_legal_url": "/attachments/download/{ATTACHMENT_ID}/{FILENAME}" }}Received invoices: original/legal file via /invoices/{id}/as/original
Section titled “Received invoices: original/legal file via /invoices/{id}/as/original”For received invoices, the original file is also the legal file. Download it directly with:
GET /invoices/{INVOICE_ID}/as/originalAttachments (both issued and received): attachments[].link
Section titled “Attachments (both issued and received): attachments[].link”The invoice JSON can include an attachments array. Each entry contains a link you can use to download the stored attachment.
attachments[].link is a relative path (not a full URL), for example:
{ "invoice": { "attachments": [ { "link": "/attachments/download/{ATTACHMENT_ID}/{FILENAME}", "content_type": "application/pdf" } ] }}For a deeper explanation of attachments and legal PDFs, see: Manage invoice attachments.
Step 2: Download the file
Section titled “Step 2: Download the file”The URL fields returned by the API (download_legal_url, attachments[].link) are relative paths. Prefix them with your environment base URL.
Download using download_legal_url (issued invoices, legal)
Section titled “Download using download_legal_url (issued invoices, legal)”curl --request GET \ --url https://api-staging.b2brouter.net{download_legal_url} \ --header 'X-B2B-API-Key: {YOUR_API_KEY}' \ --header 'X-B2B-API-Version: {YOUR_API_VERSION}'Download using attachments[].link (attachments)
Section titled “Download using attachments[].link (attachments)”curl --request GET \ --url https://api-staging.b2brouter.net{attachment_link} \ --header 'X-B2B-API-Key: {YOUR_API_KEY}' \ --header 'X-B2B-API-Version: {YOUR_API_VERSION}'Download using /invoices/{id}/as/original (original)
Section titled “Download using /invoices/{id}/as/original (original)”curl --request GET \ --url https://api-staging.b2brouter.net/invoices/{INVOICE_ID}/as/original \ --header 'X-B2B-API-Key: {YOUR_API_KEY}' \ --header 'X-B2B-API-Version: {YOUR_API_VERSION}'- For received invoices,
/invoices/{INVOICE_ID}/as/originalreturns the file received from the issuer (original = legal). - For issued invoices,
/invoices/{INVOICE_ID}/as/originalonly works when the invoice has an original file (for example, imported XML). If the invoice was created directly from a JSON payload, there may be no original file to download.