> ## 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.

# Retrieve accounting data from DATEV Rechnungswesen

> Gain exclusive early access to reading data from DATEV

## Fetch data from Datev in 5 steps

**Required**: End users must have the `Datenservice Export Rechnungswesen` enabled in their DATEV accounts
Speak to your customer success manager at Maesn to learn how to enable this service.

<Steps>
  <Step title="Authorize end user" titleSize="h3">
    Your end user must first authorize your application to access their data in DATEV Rechnungswesen Export 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="Get 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 'general requirements' below).
  </Step>

  <Step title="Retrieve the data you need" titleSize="h3">
    Fetch the data you always dreamed of retrieving from the API instead of CSV exports:

    * Retrieve GL accounts using the GET [/accounts](/api-reference/accounting-endpoints/accounts/get-accounts) endpoint
    * Retrieve fiscal years through the GET [/fiscalYears](/api-reference/accounting-endpoints/fiscalyears/get-fiscal-years) endpoint
    * Retrieve booking data using the GET [/journalEntries](/api-reference/accounting-endpoints/journalentries/get-journal-entries) endpoint
    * Retrieve payment terms through the GET [/paymentTerms](/api-reference/accounting-endpoints/paymentterms/get-payment-terms) endpoint
    * Retrieve sums and balances for your accounts using the GET [/trialBalance](/api-reference/accounting-endpoints/trialbalance/get-trial-balance) endpoint
  </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>

## Insights on endpoint `GET /accounts`

This endpoint retrieves general ledger accounts as well as customer and supplier accounts from DATEV Rechnungswesen.

The maesn API maps the account number and description to the unified model. Since some fields returned by DATEV are DATEV-specific, they are not mapped to the unified model.
However, they are still available in the raw response when using `rawData=true`.

The three DATEV specific fields are:

* **mainFunction**: the function type
* **mainFunctionNumber**: the function number
* **functionExtension**: the additional detail or extension

These fields are part of DATEV’s account-function model for SKR03 and SKR04. In addition to the account number and caption, DATEV can assign an account function to an account. This account function provides additional classification information that helps describe how the account is categorized within DATEV’s bookkeeping logic.

In the API response, this account function is represented by the fields `mainFunction`, `mainFunctionNumber`, and `functionExtension`.

To help interpret these values, DATEV publishes yearly [Kontenfunktions-Tabellen for SKR03 and SKR04](https://help-center.apps.datev.de/api/amr/knowledge-common/v1/entities/st63880273803_de.xlsx). These tables list the available account functions for a given year and provide the reference needed to understand the values returned in the API.

DATEV account-function tables use the format `ZZ YY XXX`, where:

* `ZZ` = function type
* `YY` = main function number
* `XXX` = function extension

In the API response, `mainFunction`  corresponds to the function type (`ZZ`), `mainFunctionNumber`  to the main function number (`YY`), and `functionExtension` to the function extension (`XXX`).

The following `mainFunction` values are relevant:

* `0` = no type
* `1` = automatic input tax invoice (`AV`)
* `2` = automatic VAT invoice (`AM`)
* `3` = general function (`F`)
* `4` = collective function (`S`)
* `6` = collective function, automatic input tax (`SAV`)
* `7` = collective function, automatic VAT (`SAM`)
* `8` = standard function deactivated
