Skip to content
Log in

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_url or attachments[].link).
  • An API key with access to the invoice’s project/account.
  • The internal B2Brouter invoice.id (you can obtain it from list endpoints).
Section titled “Step 1: Get the invoice payload (optional but recommended)”

Call Get invoice to retrieve the invoice JSON and locate the relevant fields:

Terminal window
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'
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:

Terminal window
GET /invoices/{INVOICE_ID}/as/original
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.

The URL fields returned by the API (download_legal_url, attachments[].link) are relative paths. Prefix them with your environment base URL.

Section titled “Download using download_legal_url (issued invoices, legal)”
Terminal window
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}'
Section titled “Download using attachments[].link (attachments)”
Terminal window
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)”
Terminal window
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/original returns the file received from the issuer (original = legal).
  • For issued invoices, /invoices/{INVOICE_ID}/as/original only 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.