Note (2026-04-24): After this document was written,
legal_entitywas renamed totenantand the oldtenantwas renamed toorganization. Read references to these terms with the pre-rename meaning.
Import historical journal entries from DATEV Rechnungswesen via Maesn API.
These are separate integrations for separate personas. Tax advisors typically have REWE access while CFOs have UO access.
booking_history_item tableALTER TYPE integration_type ADD VALUE 'datev_rewe';
CREATE TYPE booking_history_source AS ENUM ('csv_upload', 'datev_rewe');
datev_rewe_linkCREATE TABLE datev_rewe_link (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
legal_entity_id UUID NOT NULL REFERENCES legal_entity(id) ON DELETE CASCADE,
token TEXT NOT NULL UNIQUE,
expires_at TIMESTAMPTZ NOT NULL,
created_by UUID REFERENCES identity(id) ON DELETE SET NULL,
used_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_datev_rewe_link_token ON datev_rewe_link(token);
CREATE INDEX idx_datev_rewe_link_legal_entity ON datev_rewe_link(legal_entity_id);
booking_history_uploadALTER TABLE booking_history_upload
ADD COLUMN source booking_history_source NOT NULL DEFAULT 'csv_upload';
Stored in existing legal_entity_integration table:
integration_type = 'datev_rewe'credentials_encrypted = KMS-encrypted Maesn account keyconfig = {:last_sync_at ..., :company_id ...}metadata = {:company_name ..., :connected_via_link_id ...}datev_rewe_link record:
token = secure random string (32-byte URL-safe base64)expires_at = now + 7 dayscreated_by = identity of whoever generated ithttps://app.getorcha.com/connect/datev-rewe/{token}https://api.maesn.dev/auth/datev-rewe-sandbox-longtoken?environmentSelection=true
X-API-KEY: <our-maesn-api-key>{:link-token "..."}datev_rewe integration → replace (update credentials)legal_entity_integration recordused_at = now())IMPORTANT (temporary): The sync is triggered directly in the ERP handler via virtual thread, not via SQS. This is intentional for V1 simplicity. Code should include a prominent TODO comment indicating this will be migrated to a queued process handled by workers in the future.
company_idGET /accounting/journalEntries:
X-API-KEY, X-ACCOUNT-KEYfiscalYear, page, limit=100booking_history_upload record with source = 'datev_rewe', filename like "DATEV REWE Sync 2026-02-18"booking_history_item (see mapping below)legal_entity_integration.config with {:last_sync_at ...}| Maesn journal entry field | booking_history_item field |
|---|---|
Line item description or parent description |
supplier_name, supplier_name_normalized |
Line item description |
description, description_normalized |
accountNumber (DEBIT indicator) |
debit_account |
accountNumber (CREDIT indicator) |
credit_account |
First dimension code |
cost_center |
totalNetAmount |
net_amount |
Normalized fields derived using same logic as CSV upload.
Deferred to future work. When implemented:
lastModifiedAt param for incremental fetchNew section in integrations: "DATEV REWE (Historical Data)"
States:
Disconnect button follows same pattern as existing DATEV UO disconnect (soft-deactivates integration).
/connect/datev-rewe/{token} — full page renderlast_sync_at nulldisconnect_reasonGET https://api.maesn.dev/auth/datev-rewe-sandbox-longtoken?environmentSelection=true
Header: X-API-KEY: <api-key>
GET https://api.maesn.dev/accounting/journalEntries
Headers:
X-API-KEY: <api-key>
X-ACCOUNT-KEY: <account-key>
Query params:
fiscalYear (required for DATEV REWE)
page, limit (pagination)
lastModifiedAt (for incremental sync)
Response includes paginated journal entries with line items containing account numbers, amounts, dimensions (cost centers), tax info.
com.getorcha.integrations.maesn)