Skip to main content

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>
  1. In ERPNext, open the user the connector will run as: User, Settings, API Access.
  2. Click Generate Keys. Copy the API secret at once; it is shown only once.
  3. 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.

ValueWhere to find itWhere it goes
Host URLThe ERPNext site base URL, for example https://erp.mycompany.com, no trailing /apiConnector host_url
API keyUser, Settings, API AccessConnector extract_api_key
API secretUser, Settings, API AccessConnector 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 doctypeModeCursorFields requested
gl_entryGL EntryIncrementalmodifiedname, company, posting_date, fiscal_year, account, account_currency, debit, credit, against, voucher_no, voucher_type, cost_center, project, is_cancelled, remarks, modified
accountAccountFull refresh-name, account_name, root_type, account_type, company, disabled, modified
companyCompanyFull refresh-name, default_currency, country, modified
currency_exchangeCurrency ExchangeIncrementalmodifiedname, from_currency, to_currency, date, exchange_rate, modified
budgetBudget with Budget Account child lines, flattenedIncrementalmodifiedname, company, fiscal_year, cost_center, project, modified, plus account and budget_amount per line
fiscal_yearFiscal YearFull refresh-name, year_start_date, year_end_date, modified
Budget flattening

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_size ends the stream.
  • Incremental streams add the Frappe filter filters=[["modified", ">=", <state>]] and advance the high-water mark per record.
  • A Retry-After header is honoured when present; otherwise the CDK's exponential backoff applies. 5xx responses retry (capped at 5); 429 is treated as rate-limited and retried, paced by Retry-After.

Source configuration​

spec.yaml:

SettingRequiredDefaultNotes
host_urlyes-ERPNext base URL, no /api
api_keyyes-Airbyte secret
api_secretyes-Airbyte secret
page_sizeno500limit_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:

  1. Per-ERP adapter models, stg_<erp>__<entity> (for example stg_erpnext__gl_entries, stg_d365_fo__gl_entries). Each reads one ERP's raw tables and emits the same canonical column set.
  2. Canonical models, stg_<entity> (for example stg_gl_entries), UNION ALL every 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 modelERPNext adapterSource doctype
stg_gl_entriesstg_erpnext__gl_entriesGL Entry
stg_trial_balancestg_erpnext__trial_balancederived from GL Entry
stg_accountsstg_erpnext__accountsAccount
stg_legal_entitiesstg_erpnext__legal_entitiesCompany
stg_exchange_ratesstg_erpnext__exchange_ratesCurrency Exchange
stg_budget_entriesstg_erpnext__budget_entriesBudget
stg_fiscal_periodsstg_erpnext__fiscal_periodsFiscal 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_center to dim_cost_center, project to dim_business_unit). amount is debit - credit (signed); silver derives debit and credit from the sign. record_id is reinterpretAsInt64(cityHash64(name)) so it unions with D365's numeric SourceKey. entity_id is upper(company). fiscal_period is the calendar month of posting_date. Rows with is_cancelled in 1, yes, true are dropped.
  • Account (stg_erpnext__accounts.sql): root_type (Asset, Liability, Income, Expense, Equity) becomes the canonical account_type; ERPNext's finer account_type becomes account_category. account_id is the Account name, which is what GL Entry.account references.
  • Company (stg_erpnext__legal_entities.sql): ERPNext has no short company code, so entity_id is upper(name), matching the GL and budget adapters.
  • Currency Exchange (stg_erpnext__exchange_rates.sql): rates are point-in-time, so valid_from is the date and valid_to is the open-ended 2099-12-31; rate_type is 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-01 is used. record_id is a deterministic UInt64 hash of name and account.
  • Fiscal Year (stg_erpnext__fiscal_periods.sql): fiscal years are named ranges (2024-2025) with explicit start and end dates; the name is both calendar_id and the canonical fiscal_year label.
  • Trial balance (stg_erpnext__trial_balance.sql): ERPNext has no trial-balance snapshot doctype, so the adapter aggregates GL Entry per entity, account and fiscal year; opening_balance is 0 and closing_balance is sum(debit - credit).

Troubleshooting​

IssueCauseFix
Authentication failed (HTTP 401/403) on checkWrong host_url, key or secret, or the user lacks read accessUse Test Extract on the Connector; grant read on the six doctypes
Empty or partial GL syncCancelled rows are filteredExpected
429 or slow syncERPNext rate limitingThe stream honours Retry-After; lower extract_page_size
Budget rows missing accountsThe Budget has no Budget Account linesOne row per line; no lines, no rows
Rows in epm_raw, nothing in silver or golderpnext is not in erp_sourcesSet erp_sources: [erpnext] in dbt_project.yml, commit, rebuild
Connector Health Stale or NeverWebhook not configured, or the sync does not runSee Monitoring

Next steps​