Send an email with an invoice file attached

Create an issued invoice

In the example below, you'll learn how to generate an issued invoice with the delivery method set to email.

To send an invoice through email, ensure that the transport_type_code is set to email and provide a valid email(email address). Additionally, make sure to specify the document_type_code that you want to be attached to the email. In this example, it's set to xml.ubl.invoice.xrechnung.v22

curl --location 'https://app.b2brouter.net/projects/{project-id}/invoices.json' \
--header 'X-B2B-API-Key: xxxxxxx' \
--header 'Content-Type: application/json' \

--data-raw '{
 "send_after_import": false,
  "invoice": {
    "number": "2",
    "date": "2024-03-27",
    "due_date": "2024-03-29",
    "terms": "custom",
    "ponumber": "1",
    "buyer_reference": "01002-000005228-65",
    "client": {
        "name": "Universität Bielefeld",
        "taxcode": "0204:05-NRW-83",
        "address": "Universitätsstraße 25",
        "postalcode": "33615",
        "city": "Bielefeld",
        "province": "Bielefeld",
        "country": "de",
        "email": "[email protected]",
        "transport_type_code": "email",
        "document_type_code": "xml.ubl.invoice.xrechnung.v22",
        "contact": "John Doe"
    },
    "invoice_lines_attributes": [
      {
        "unit": 1,
        "quantity": 1,
        "price": 1,
        "description": "Description line",
        "article_code": "Article Code",
        "taxes_attributes": [
          {
            "category": "S",
            "name": "MwSt",
            "percent": 19
          }
        ]
      }
    ]
}
}'

Send the invoice

Before transmission, we meticulously verify the presence of all required data and validate the document against the transport and document type requirements. This ensures that the invoice meets all necessary criteria for successful delivery.

Link to API Reference

# Send invoice 
curl --location --request POST 'http:/app.b2brouter.net/invoices/send_invoice/{invoice-id}.json' 
--header 'X-B2B-API-KEY: xxxxxxxxxxx' 
--header 'Content-Type: application/json' 

Trace your invoice

When it comes to invoices sent via email, traceability of the status is limited. You can primarily verify if the invoice has been successfully sent, in which case its status would be sent. Conversely, if an error occurred during the sending process, resulting in the invoice not being sent, the status would be changed to error. This status update indicates that the invoice encountered an issue and couldn't be delivered.