Send invoices (end-to-end)
Send invoices (end-to-end)
This guide shows a clean API flow to send invoices: create or reuse a contact, create or import an invoice, send it, and retrieve the final files.
Prerequisites
- API Key:
X-B2B-API-Key - API Version:
X-B2B-API-Version ACCOUNT_ID: the account that issues the invoice.
Important IDs:
ACCOUNT_ID: owner account (path param in/accounts/{ACCOUNT_ID}/...).CONTACT_ID: recipient contact (stored inside the account).INVOICE_ID: invoice identifier (used in/invoices/{INVOICE_ID}...endpoints).
1) Get or create the recipient contact
1.1) Lookup contacts (optional)
curl --request GET \
--url 'https://api-staging.b2brouter.net/accounts/{ACCOUNT_ID}/contacts?offset=0&limit=25&name=Example%20Customer' \
--header 'X-B2B-API-Key: {YOUR_API_KEY}' \
--header 'X-B2B-API-Version: {YOUR_API_VERSION}' \
--header 'accept: application/json'1.2) Lookup in the directory (optional)
If you know the recipient’s identifier and country, you can retrieve public information from the directory and use it to build the contact.
curl --request GET \
--url https://api-staging.b2brouter.net/directory/es/ESB63276174 \
--header 'X-B2B-API-Key: {YOUR_API_KEY}' \
--header 'X-B2B-API-Version: {YOUR_API_VERSION}' \
--header 'accept: application/json'1.3) Create a contact (if you don’t have one)
curl --request POST \
--url https://api-staging.b2brouter.net/accounts/{ACCOUNT_ID}/contacts \
--header 'X-B2B-API-Key: {YOUR_API_KEY}' \
--header 'X-B2B-API-Version: {YOUR_API_VERSION}' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"contact": {
"name": "Example Customer",
"country": "es",
"is_client": true,
"email": "[email protected]",
"tin_scheme": "9920",
"tin_value": "ESB00000000",
"transport_type_code": "b2brouter",
"document_type_code": "json"
}
}'Note: CONTACT_ID is returned in the response. Do not confuse it with ACCOUNT_ID.
2) Create (JSON) or import (XML) the invoice
2.1) Create invoice using JSON
curl --request POST \
--url https://api-staging.b2brouter.net/accounts/{ACCOUNT_ID}/invoices \
--header 'X-B2B-API-Key: {YOUR_API_KEY}' \
--header 'X-B2B-API-Version: {YOUR_API_VERSION}' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"send_after_import": false,
"invoice": {
"type": "IssuedInvoice",
"contact_id": {CONTACT_ID},
"number": "INV-0001",
"date": "2026-01-21",
"terms": "custom",
"due_date": "2026-02-21",
"currency": "EUR",
"invoice_lines_attributes": [
{
"quantity": 1,
"price": 10,
"description": "Example service",
"taxes_attributes": [
{ "name": "VAT", "category": "S", "percent": 21 }
]
}
]
}
}'2.2) Import invoice from a file (when you already generate XML)
curl --request POST \
--url 'https://api-staging.b2brouter.net/accounts/{ACCOUNT_ID}/invoices/import?send_after_import=false' \
--header 'X-B2B-API-Key: {YOUR_API_KEY}' \
--header 'X-B2B-API-Version: {YOUR_API_VERSION}' \
--header 'content-type: application/octet-stream' \
--data 'data:text/xml;name=invoice.xml;base64,PD94bWw+Li4u'3) Send the invoice
curl --request POST \
--url https://api-staging.b2brouter.net/invoices/send_invoice/{INVOICE_ID} \
--header 'X-B2B-API-Key: {YOUR_API_KEY}' \
--header 'X-B2B-API-Version: {YOUR_API_VERSION}'4) Retrieve the invoice and download final files
4.1) Get the invoice payload
curl --request GET \
--url https://api-staging.b2brouter.net/invoices/{INVOICE_ID}?include=lines \
--header 'X-B2B-API-Key: {YOUR_API_KEY}' \
--header 'X-B2B-API-Version: {YOUR_API_VERSION}' \
--header 'accept: application/json'4.2) Download legal/original invoice files
Follow: https://developer.b2brouter.net/docs/download_legal_or_original_invoice
Related guides
- Payment methods: https://developer.b2brouter.net/docs/payment_method_guide#/
- Invoice calculation: https://developer.b2brouter.net/docs/invoice_calculation#/
- Send invoice via JSON (Peppol example): https://developer.b2brouter.net/docs/send_an_invoice_through_peppol_via_json_payload#/
Updated about 2 hours ago