ERPNext Integration
How Konsolidat extracts data from ERPNext (Frappe) over the REST API, and how the ERPNext adapter plugs into the canonical staging interface so that silver and gold stay ERP-agnostic. Verified against source-erpnext/source_erpnext/{auth,source,streams}.py, spec.yaml, dbt_project/models/staging/erpnext/ and the konsol Connector doctype on 2026-11-05.
The connector lives in source-erpnext/ (an Airbyte CDK source) and lands raw doctypes in the ClickHouse database epm_raw. The dbt adapter models stg_erpnext__* transform those raw tables into the same canonical schema every other adapter produces.
API access (Frappe token)
ERPNext authenticates API calls with a static token header; there is no OAuth exchange (auth.py):
Authorization: token <api_key>:<api_secret>
- In ERPNext, open the user the connector will run as: User, Settings, API Access.
- Click Generate Keys. Copy the API secret at once; it is shown only once.
- Give that user read access to GL Entry, Account, Company, Currency Exchange, Budget and Fiscal Year.
The connector validates credentials on check by calling frappe.auth.get_logged_user. A failure returns a short, non-sensitive message and never echoes the server body.
| Value | Where to find it | Where it goes |
|---|---|---|
| Host URL | The ERPNext site base URL, for example https://erp.mycompany.com, no trailing /api | Connector host_url |
| API key | User, Settings, API Access | Connector extract_api_key |
| API secret | User, Settings, API Access | Connector extract_api_secret |
The Connector document
Create one Connector (Desk, module Pipeline) with erp_type = erpnext. The ERPNext fields appear in the Extract Credentials tab: host_url, extract_api_key, extract_api_secret, plus extract_page_size (default 100). List the entities it serves in the Legal Entities tab (the entity_id is the upper-cased ERPNext company name; see below) and map dimension columns in the Dimension Mappings tab.
Form actions under the Airbyte button group: Test Extract validates the key against the live site; Test & Provision Airbyte creates or updates the Airbyte source and connection through the public API, using EPM Settings airbyte_erpnext_source_definition_id. Write-back for ERPNext uses writeback_api_key and writeback_api_secret when writeback_credentials_separate is set.
Airbyte itself is installed with scripts/setup-airbyte.sh; the destination is ClickHouse at 172.30.0.10:8123, database epm_raw. See D365 Integration for the Airbyte steps, which are the same for every connector.
Doctype streams
The connector ships 6 streams (source.py, streams.py), one per doctype. Each reads /api/resource/<DocType> with limit_start and limit_page_length paging (page_size, default 500), ordered modified asc. Master streams full-refresh; transactional streams sync incrementally on modified.
| Stream (raw table) | ERPNext doctype | Mode | Cursor | Fields requested |
|---|---|---|---|---|
gl_entry | GL Entry | Incremental | modified | name, company, posting_date, fiscal_year, account, account_currency, debit, credit, against, voucher_no, voucher_type, cost_center, project, is_cancelled, remarks, modified |
account | Account | Full refresh | - | name, account_name, root_type, account_type, company, disabled, modified |
company | Company | Full refresh | - | name, default_currency, country, modified |
currency_exchange | Currency Exchange | Incremental | modified | name, from_currency, to_currency, date, exchange_rate, modified |
budget | Budget with Budget Account child lines, flattened | Incremental | modified | name, company, fiscal_year, cost_center, project, modified, plus account and budget_amount per line |
fiscal_year | Fiscal Year | Full refresh | - | name, year_start_date, year_end_date, modified |
The Frappe list endpoint omits child tables. The budget stream fetches each Budget document's detail (/api/resource/Budget/<name>) and emits one row per Budget Account child line, copying the parent fields (company, fiscal year, cost center, project) onto each row. A budget with no lines emits no rows.
Paging, incremental, backoff
- A page shorter than
page_sizeends the stream. - Incremental streams add the Frappe filter
filters=[["modified", ">=", <state>]]and advance the high-water mark per record. - A
Retry-Afterheader is honoured when present; otherwise the CDK's exponential backoff applies.5xxresponses retry (capped at 5);429is treated as rate-limited and retried, paced byRetry-After.
Source configuration
spec.yaml:
| Setting | Required | Default | Notes |
|---|---|---|---|
host_url | yes | - | ERPNext base URL, no /api |
api_key | yes | - | Airbyte secret |
api_secret | yes | - | Airbyte secret |
page_size | no | 500 | limit_page_length; 50 to 5000 |
Raw tables are declared as the dbt source erpnext_raw in _erpnext__sources.yml (database epm_raw), with freshness on gl_entry: warn after 24 hours, error after 48. The connector also runs standalone for local testing:
cd source-erpnext && pip install -e .
source-erpnext spec
source-erpnext check --config secrets/config.json
source-erpnext read --config secrets/config.json --catalog integration_tests/configured_catalog.json
Canonical staging architecture
Konsolidat supports several ERPs behind one canonical staging interface:
- Per-ERP adapter models,
stg_<erp>__<entity>(for examplestg_erpnext__gl_entries,stg_d365_fo__gl_entries). Each reads one ERP's raw tables and emits the same canonical column set. - Canonical models,
stg_<entity>(for examplestg_gl_entries),UNION ALLevery enabled adapter and harmonize dimensions centrally. Bronze, silver and gold read only these.
Which adapters are built and unioned is the dbt var erp_sources in dbt_project/dbt_project.yml. It defaults to empty (konsolidat#207): no ERP adapter builds, and trial-balance uploads are the canonical source.
vars:
erp_sources: [] # set [erpnext], or [d365_fo, erpnext], and commit
This is a hand edit. konsol/dbt_config.py regenerates dimensions, base_measures and the fiscal vars and deliberately leaves erp_sources alone: an enabled Connector says nothing about its data having landed, and deriving the list from connector state once enabled adapters whose raw tables were empty and broke the whole build (konsolidat#139). Every stg_erpnext__* model starts with config(enabled = 'erpnext' in var('erp_sources', [])), and the canonical models loop over the same var:
{% set erp_sources = var('erp_sources', []) %}
with unioned as (
{% for erp in erp_sources %}
select ... from {{ ref('stg_' ~ erp ~ '__gl_entries') }}
{% if not loop.last %}union all{% endif %}
{% endfor %}
)
Adding an ERP is additive: ship its stg_<erp>__* adapters with the canonical column contract and add the key to erp_sources. No silver or gold change.
Dimension harmonization
stg_gl_entries takes dimension values raw from each adapter and harmonizes them centrally, keyed on the per-row erp_source, with the dim_harmonize_select and dim_harmonize_joins macros (macros/dimension_helpers.sql). Unmapped values pass through unchanged. The mapping rows come from the konsol Dimension Mapping doctype, written to epm_staging.dimension_mappings.
ERPNext adapter mapping
Every adapter stamps 'erpnext' as erp_source; _loaded_at and _raw_id come from _airbyte_extracted_at and _airbyte_raw_id.
| Canonical model | ERPNext adapter | Source doctype |
|---|---|---|
stg_gl_entries | stg_erpnext__gl_entries | GL Entry |
stg_trial_balance | stg_erpnext__trial_balance | derived from GL Entry |
stg_accounts | stg_erpnext__accounts | Account |
stg_legal_entities | stg_erpnext__legal_entities | Company |
stg_exchange_rates | stg_erpnext__exchange_rates | Currency Exchange |
stg_budget_entries | stg_erpnext__budget_entries | Budget |
stg_fiscal_periods | stg_erpnext__fiscal_periods | Fiscal Year |
Transforms applied in the adapters (read the SQL for the full column list):
- GL Entry (
stg_erpnext__gl_entries.sql): ERPNext stores each posting as a separate debit or credit row, with dimensions as flat columns (cost_centertodim_cost_center,projecttodim_business_unit).amountisdebit - credit(signed); silver derives debit and credit from the sign.record_idisreinterpretAsInt64(cityHash64(name))so it unions with D365's numericSourceKey.entity_idisupper(company).fiscal_periodis the calendar month ofposting_date. Rows withis_cancelledin1,yes,trueare dropped. - Account (
stg_erpnext__accounts.sql):root_type(Asset, Liability, Income, Expense, Equity) becomes the canonicalaccount_type; ERPNext's fineraccount_typebecomesaccount_category.account_idis the Accountname, which is whatGL Entry.accountreferences. - Company (
stg_erpnext__legal_entities.sql): ERPNext has no short company code, soentity_idisupper(name), matching the GL and budget adapters. - Currency Exchange (
stg_erpnext__exchange_rates.sql): rates are point-in-time, sovalid_fromis thedateandvalid_tois the open-ended2099-12-31;rate_typeis empty. Consolidation translates at the governed Group Exchange Rates in konsol, not at these. - Budget (
stg_erpnext__budget_entries.sql): reads the flattened rows. ERPNext budgets have no posting date, so<fiscal year>-01-01is used.record_idis a deterministicUInt64hash ofnameandaccount. - Fiscal Year (
stg_erpnext__fiscal_periods.sql): fiscal years are named ranges (2024-2025) with explicit start and end dates; thenameis bothcalendar_idand the canonicalfiscal_yearlabel. - Trial balance (
stg_erpnext__trial_balance.sql): ERPNext has no trial-balance snapshot doctype, so the adapter aggregatesGL Entryper entity, account and fiscal year;opening_balanceis 0 andclosing_balanceissum(debit - credit).
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
Authentication failed (HTTP 401/403) on check | Wrong host_url, key or secret, or the user lacks read access | Use Test Extract on the Connector; grant read on the six doctypes |
| Empty or partial GL sync | Cancelled rows are filtered | Expected |
429 or slow sync | ERPNext rate limiting | The stream honours Retry-After; lower extract_page_size |
| Budget rows missing accounts | The Budget has no Budget Account lines | One row per line; no lines, no rows |
Rows in epm_raw, nothing in silver or gold | erpnext is not in erp_sources | Set erp_sources: [erpnext] in dbt_project.yml, commit, rebuild |
Connector Health Stale or Never | Webhook not configured, or the sync does not run | See Monitoring |
Next steps
- D365 F&O Integration: the other shipped adapter, and the Airbyte install
- Initial Setup Guide: entities, chart, connectors
- Bronze Models