Enviar factura por SDI
Receta rápida para emitir una factura al SDI (Sistema di Interscambio) con la API de B2Brouter: cuenta → contacto → factura → estado.
1. Crear la cuenta de la empresa italiana
Sección titulada «1. Crear la cuenta de la empresa italiana»curl --request POST \ --url https://api-staging.b2brouter.net/accounts \ --header 'X-B2B-API-Key: {YOUR_API_KEY}' \ --header 'X-B2B-API-Version: {YOUR_API_VERSION}' \ --header 'content-type: application/json' \ --data '{ "account": { "country": "it", "tin_value": "20339260422", "tin_scheme": 211, "name": "Test Sender Italy", "address": "Milano street, 1", "city": "Milano", "postalcode": "20019", "province": "MI", "tax_regime": "RF01" } }'2. Crear el contacto de cliente
Sección titulada «2. Crear el contacto de cliente»transport_type_code: it.sdi, document_type_code: xml.fatturapa.1.2, la Partita IVA con tin_scheme: 9906 (o el Codice Fiscale con cin_scheme: 9907), y el Codice Destinatario en recipient_code (si no tiene, 0000000).
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 'content-type: application/json' \ --data '{ "contact": { "tin_scheme": "9906", "tin_value": "IT12345678901", "name": "Esempio S.r.l.", "address": "Via Inventata 88", "postalcode": "00184", "city": "Roma", "province": "RM", "country": "it", "transport_type_code": "it.sdi", "document_type_code": "xml.fatturapa.1.2", "recipient_code": "{CODICE_DESTINATARIO}" } }'3. Crear y enviar la factura
Sección titulada «3. Crear y enviar la factura»Con send_after_import: true la factura se envía directamente al SDI.
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 'content-type: application/json' \ --data '{ "send_after_import": true, "invoice": { "type": "IssuedInvoice", "number": "1", "date": "2025-01-22", "contact_id": {YOUR_CONTACT_ID}, "invoice_lines_attributes": [ { "quantity": 10, "price": 47, "description": "Test Item", "taxes_attributes": [{ "name": "IVA", "percent": 22 }] } ] } }'4. Comprobar el estado
Sección titulada «4. Comprobar el estado»curl --request GET \ --url 'https://api-staging.b2brouter.net/invoices/{INVOICE_ID}' \ --header 'X-B2B-API-Key: {YOUR_API_KEY}' \ --header 'X-B2B-API-Version: {YOUR_API_VERSION}' \ --header 'accept: application/json'La factura pasa por sending → sent; si el SDI la rechaza, pasa a error. Consulta Comprobar el estado de la factura para los detalles y el paso de acknowledge.