> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maesn.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Capture invoices & bills in DATEV Unternehmen Online

> Implement easy generation and transfer of booking proposals to DATEV for accounting and tax purposes

There are two different ways to capture invoices, bills and credit notes as booking proposals in DATEV Unternehmen Online:

1. Upload documents, e.g., PDF-files, and letting Unternehmen Online capture the data using optical character recognition (OCR)
2. Upload the documents together with structured data to provide more detail than visible on the document and avoid mistakes due to OCR-failures

The two approaches are described in the respective sections below.

## Upload files to Datev in 7 steps

**Required**: Before getting started, ensure that your end users have the `Belegbilderservice` enabled in their DATEV accounts

<Steps>
  <Step title="Authorize end user" titleSize="h3">
    Your end user must first authorize your application to access their data in DATEV Unternehmen Online through [maesn Connect](/guides/maesn-connect).
  </Step>

  <Step title="Retrieve companies" titleSize="h3">
    Fetch all the companies associated to your end users's DATEV account using the GET [/companies](/api-reference/auth/get-companies) endpoint. The user will need to select a company to proceed, as the company ID will be needed for subsequent steps.
    Note that you can use the [interactive authentication flow](/authentication#interactive-authentication-flow) to eliminate this step.
  </Step>

  <Step title="Retrieve user info" titleSize="h3">
    Fetch the user info associated to your end users's DATEV account using the GET [/userInfo](/api-reference/user-endpoints/user/user-info) endpoint. Display the retrieved information in your application's UI as required by DATEV (see 'general requirements' below).
  </Step>

  <Step title="Retrieve document types (optional)" titleSize="h3">
    Fetch the relevant document types from your end users's DATEV account using the GET [/documentTypes](/api-reference/accounting-endpoints/files/get-document-types) endpoint. The document types will be used to categorize the files you will upload. These may, for example, be presented to the end user as a drop-down menu at the point of file upload.
    <ul> <strong>IMPORTANT</strong>: it is sufficient to call the endpoint only once per user, as the document types are not expected to change frequently.</ul>
  </Step>

  <Step title="Check document extensions (optional)" titleSize="h3">
    If necessary, confirm the file extensions supported by the selected end user company (Mandant) by calling the GET [/document-extensions](/api-reference/accounting-endpoints/files/get-document-extensions).
    <ul> <strong>IMPORTANT</strong>: like in the step above, this endpoint should be called only once per user.</ul>
  </Step>

  <Step title="Upload the document" titleSize="h3">
    Upload the document to DATEV using the POST [/files](/api-reference/accounting-endpoints/files/upload-file) endpoint. Make sure to include all the required fields in the request body. Ensure your application checks the file size before uploading to avoid performance issues (see last step).
  </Step>

  <Step title="Check DATEV general requirements" titleSize="h3">
    Review the DATEV interface [requirements](https://developer.datev.de/en/guides/interface-requirements) to ensure that your application complies with DATEV’s specifications.
  </Step>
</Steps>

Optional:

<Steps>
  <Step title="Delete end user" stepNumber="0" titleSize="h3">
    If your user deletes their account, you may delete the end user from our API and revoke their token using the the POST [/delete-end-users](/api-reference/accounting-endpoints/tenants/delete-end-user). This step ensures both actions are handled on the backend.
  </Step>
</Steps>

## Upload files together with structured data to Datev in 7 steps

**Required**: Before getting started, ensure that your end users have the `Rechnungsdatenservice 1.0` enabled in their DATEV accounts.  In addition, they must have at least one `fiscal year` set up and the necessary access rights to write `accounts payable (bills)` and `accounts receivable (invoices)`.
These permissions are required for posting financial data through the API.

<Steps>
  <Step title="Authorize end user" titleSize="h3">
    Your end user must first authorize your application to access their data in DATEV Rechnungswesen through [maesn Connect](/guides/maesn-connect).
  </Step>

  <Step title="Get companies" titleSize="h3">
    Fetch all the companies associated to your end users's DATEV account using the GET [/companies](/api-reference/auth/get-companies) endpoint. The user will need to select a company to proceed, as the company ID will be needed for subsequent steps.
    Note that you can use the [interactive authentication flow](/authentication#interactive-authentication-flow) to eliminate this step.
  </Step>

  <Step title="Retrieve user info (optional)" titleSize="h3">
    Fetch the user info associated to your end users's DATEV account using the GET [/userInfo](/api-reference/user-endpoints/user/user-info) endpoint. Display the retrieved information in your application's UI as required by DATEV (see last step).
  </Step>

  <Step title="Retrieve ledgers" titleSize="h3">
    Fetch the available ledgers from your end users's DATEV account using the GET [/accounts](/api-reference/accounting-endpoints/accounts/get-accounts) endpoint. The user will need to select a ledger to proceed, as the ledger is required for the subsequent steps.
  </Step>

  <Step title="Create booking proposals" titleSize="h3">
    Create the booking proposal and upload it to DATEV Unternehmen Online using the POST [/bookingProposals](/api-reference/accounting-endpoints/bookingproposals/create-booking-proposal) endpoint. Make sure to include all the required fields in the request body. You can include multiple files in the request.
  </Step>

  <Step title="Check status" titleSize="h3">
    Check the status of the upload using the GET [/asyncTask](/api-reference/accounting-endpoints/asynctask) endpoint. This will allow you to verify if the upload was successfully processed by DATEV.
    Read more about asynchronous tasks [here](/async-task)
  </Step>

  <Step title="Check DATEV general requirements" titleSize="h3">
    Review the DATEV interface [requirements](https://developer.datev.de/en/guides/interface-requirements) to ensure that your application complies with DATEV’s specifications.
  </Step>
</Steps>

Optional:

<Steps>
  <Step title="Delete end user" stepNumber="0" titleSize="h3">
    If your user deletes their account, you may delete the end user from our API and revoke their token using the the POST [/delete-end-users](/api-reference/accounting-endpoints/tenants/delete-end-user). This step ensures both actions are handled on the backend.
  </Step>
</Steps>
