> For the complete documentation index, see [llms.txt](https://docs.younium.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.younium.com/e-invoicing-integrations/auto-invoice.md).

# AutoInvoice

## Synchronisation scope

| Synchronisation                                 | Direction             | When it runs                                                                                                                  |
| ----------------------------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| Invoices and credit notes (electronic delivery) | Younium → AutoInvoice | When an invoice with delivery method Electronic invoice or Automatic electronic routing is posted, or resent from the invoice |
| Invoices and credit notes (external print)      | Younium → AutoInvoice | When an invoice with delivery method External print is posted, or resent from the invoice                                     |
| E-invoice status                                | AutoInvoice → Younium | When AutoInvoice reports that an invoice was delivered or failed                                                              |

Not in scope: received (supplier) invoices, payments.

***

## Overview

The AutoInvoice integration connects Younium to Maventa’s AutoInvoice service for Peppol BIS 3.0 e-invoice distribution. On invoice post (or resend), Younium builds Peppol UBL XML, optionally validates it against Maventa’s validation API, uploads the file to Maventa, and stores the generated XML on the invoice. The integration also manages OAuth credentials, company–vendor linking, and routing preferences (electronic, print, email).

## Authentication

AutoInvoice is delivered through Maventa, so what you connect is a Maventa account. You enter the client id and secret Maventa issued you on the integration settings and save; Younium signs in with them and links your company to Younium as its vendor at Maventa in the same step.

If both succeed the integration is active. If either fails, the integration is left inactive and the message Maventa gave is shown, so a failed connection says what Maventa objected to. Saving without a client id and secret is refused outright.

Younium manages its own access from then on, renewing it well before it lapses, so the connection stays live without intervention.

### Settings

| Setting                        | Description                                                               | Default       |
| ------------------------------ | ------------------------------------------------------------------------- | ------------- |
| `UseElectronicInvoiceOperator` | Send the account's electronic invoice operator to Maventa when one is set | Tenant choice |
| `SkipPreValidation`            | Skip Maventa's validation of the invoice before it is posted              | `false`       |
| `DefaultYourReference`         | Used for Peppol when the invoice has no *your reference*                  | Empty         |
| `DefaultOurReference`          | Used when the invoice has no *our reference*                              | Empty         |
| `DefaultBuyerReference`        | Used as the buyer reference when the invoice has none                     | Empty         |

## Sandbox vs. Production

Younium connects to Maventa's production service from a production environment and to Maventa's test service everywhere else. It is not a choice you make in the settings — it follows the Younium environment you are working in, so a test tenant cannot send a real invoice.

## Activation and Save settings

Saving the settings is what activates the integration: Younium signs in to Maventa with the credentials you entered and registers your company as linked to Younium. Both have to succeed for the integration to become active.

If either fails, the integration stays inactive and the error from Maventa is reported. Nothing is sent until it is active.

## Deactivation

Disconnecting removes the link between your company and Younium at Maventa, clears the stored credentials, and marks the integration inactive. Posting an invoice in Younium no longer sends it through AutoInvoice.

Invoices already sent are unaffected — they remain with Maventa and continue on their way to the recipient.

## Post e-invoice workflow

Triggered from invoice posting flows with flags `postElectronicInvoiceAsPrint`, `postAutomaticElectronicRouting`, optional attachment list, and `resendInvoice`.

1. Load the invoice attachments, either from the repost list or from the attachments stored on the invoice.
2. Generate the Peppol UBL XML for the invoice (see the [Peppol](https://docs.younium.com/e-invoicing-integrations/peppol.md) article).
3. Unless **Skip pre-validation** is on, validate the XML before sending; a document that fails validation is rejected with the validation errors.
4. OAuth `Auth()`.
5. Multipart POST to `/v1/invoices` (mapping in Maventa article).
6. On success, attach XML via `fileService.AttachAutomaticInvoiceXML` with status `AutoGeneratedXMLOnPost`.
7. Return deserialized Maventa response (dynamic JSON).

Failure throws with Maventa `code`, `message`, and `details`.

## Validation response mapping

| Maventa validation field           | Younium handling               |
| ---------------------------------- | ------------------------------ |
| `result` `OK` or `WARNING`         | Treated as success             |
| `message`, `code`                  | Error message prefix           |
| `assertions` with `status` `ERROR` | Aggregated into exception text |

## Connection and invoice enquiry

| Action             | Endpoint                           | Auth   |
| ------------------ | ---------------------------------- | ------ |
| Connection details | GET `/oauth2/current`              | Bearer |
| Invoice details    | GET `/v1/invoices/{autoInvoiceId}` | Bearer |

## Create UBL without post

`CreateUBLDocument` returns Peppol XML bytes for download or manual use; same generation path as post without Maventa upload.

## Eligibility

Requires legal entity **EnableAutoInvoice** (with electronic invoice enablement checks in core). Account should have invoice email and/or electronic routing fields where routing is used. Peppol pre-validation rules apply before XML is built.

## Field mapping summary (post payload)

| Younium source                      | Maventa form field         |
| ----------------------------------- | -------------------------- |
| Peppol XML outer XML                | `file`                     |
| `Invoice.InvoiceNumber`             | XML filename               |
| `Invoice.Id`                        | `uuid` (omitted on resend) |
| `Account.InvoiceEmailAddress`       | `recipient_email`          |
| `Account.ElectronicInvoiceOperator` | `recipient_operator`       |
| Post flags                          | `disabled_routes`          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.younium.com/e-invoicing-integrations/auto-invoice.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
