D365 F&O Integration
How Konsolidat extracts data from Dynamics 365 Finance & Operations with the Airbyte source connector in source-d365-fno/, and how the rows reach the dbt models. Verified against source-d365-fno/source_d365_fno/{auth,source,streams}.py, dbt_project/models/staging/d365_fo/, scripts/setup-airbyte.sh and the konsol Connector doctype on 2026-11-05.
Overview
- An Azure app registration gives the connector a service principal with application permissions on D365.
- A Connector document in konsol (Desk, module Pipeline) holds the credentials, the legal entities served, and the Airbyte connection id.
- Airbyte runs the
source-d365-fnoconnector and lands raw rows in ClickHouse databaseepm_raw, one table per stream. - dbt adapter models
stg_d365_fo__*map the raw rows to the canonical staging schema. They build only whend365_fois listed in the dbt varerp_sources. - Bronze, silver and gold read the canonical models and never an ERP table.
Azure AD app registration
- Open Azure Portal, App registrations and click New registration. Name:
Konsolidat Airbyte. Single tenant. No redirect URI. - Note the Application (client) ID and Directory (tenant) ID.
- Under Certificates & secrets, create a client secret and copy the value at once; it is shown only once.
- Under API permissions, add Dynamics ERP (Dynamics 365 Finance and Operations), choose Application permissions, pick the access role your tenant exposes (for example
Connector.FullAccessorAX.FullAccess), and Grant admin consent. - In D365, open System administration, Setup, Microsoft Entra ID applications and register the client ID with a user account that has the data-access permissions. Without this step the token is issued but every OData call returns
401.
The connector authenticates with the OAuth2 client-credentials flow (auth.py): grant_type=client_credentials against https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token with scope {environment_url}/.default. There is no signed-in user, so delegated permissions do not work.
| Value | Where to find it | Where it goes |
|---|---|---|
| Tenant ID | App registration, Overview | Connector tenant_id |
| Client ID | App registration, Overview | Connector extract_client_id |
| Client secret | Certificates & secrets | Connector extract_client_secret |
| Environment URL | D365, System administration; looks like https://yourorg.operations.dynamics.com | Connector environment_url |
The Connector document
Create one Connector per D365 environment (Desk: Connector, New; or konsol connector create --erp-type d365_fo ... with the CLI).
| Tab | Field | Notes |
|---|---|---|
| Connector | connector_name, erp_type = d365_fo, enabled | dbt_adapter_prefix (stg_d365_fo) and airbyte_source are derived |
| Connector | airbyte_source_id, airbyte_connection_id | Filled by Test & Provision Airbyte, or pasted from the Airbyte UI |
| Connector | sync_frequency_minutes (default 1440) | Threshold for the Stale health status |
| Extract Credentials | tenant_id, environment_url, extract_client_id, extract_client_secret | Shown for d365_fo and d365_bc |
| Extract Options | extract_page_size (default 100), extract_cross_company (default on) | Passed to the Airbyte source as page_size and cross_company |
| Write-Back Credentials | writeback_enabled, optional separate credentials, writeback_fiscal_year_start_month | Budget write-back to BudgetRegisterEntries |
| Legal Entities | Connector Legal Entity rows (entity_id, entity_name) | Which entities this connector serves; scopes connector health |
| Dimension Mappings | Connector Dimension Map rows (dimension, source_column) | This ERP's column per canonical dimension |
Form actions, under the Airbyte button group:
- Test Extract (
test_extract_connection) checks the credentials against the live D365 token endpoint. - Test Writeback (
test_writeback_connection) does the same for the write-back credentials. - Test & Provision Airbyte (
provision_airbyte) tests the extract credentials, then creates or updates the Airbyte source and the connection to the ClickHouse destination through Airbyte's public API (/api/public/v1), using EPM Settingsairbyte_api_url,airbyte_client_id,airbyte_client_secret,airbyte_workspace_id,airbyte_destination_idandairbyte_d365_source_definition_id.
Permissions follow the Build Governance roles: System Manager and EPM Admin full access; EPM Analyst read and create; EPM User read.
Installing Airbyte
Airbyte is a second stack on the same host, installed by abctl into its own local Kubernetes (kind) cluster:
bash scripts/setup-airbyte.sh
The script installs abctl if needed, runs abctl local install, and attaches the kind node container to the open_epm Docker network so sync pods can reach ClickHouse. It then prints the UI URL (http://localhost:8000), the login (abctl local credentials) and the destination settings. Airbyte pods resolve names through CoreDNS, not Docker DNS, so the destination host must be ClickHouse's pinned IP, not the container name.
| Destination setting | Value |
|---|---|
| Type | ClickHouse |
| Host | 172.30.0.10 (pinned on the open_epm network; EPM Settings airbyte_clickhouse_host) |
| Port | 8123 (the container port, whatever CLICKHOUSE_HTTP_PORT is) |
| Database | epm_raw (EPM Settings airbyte_clickhouse_database) |
| User, password | CLICKHOUSE_USER, CLICKHOUSE_PASSWORD from .env |
Load the custom connector from source-d365-fno/ (Dockerfile included) through Airbyte's custom connector settings, and record its source definition id in EPM Settings (airbyte_d365_source_definition_id) so Test & Provision Airbyte can use it. Set the Airbyte webhook to https://<SITE_DOMAIN>/api/method/konsol.api.airbyte_sync_complete with the X-Webhook-Secret header from EPM Settings so sync status reaches konsol (see Monitoring).
This local-kind Airbyte is a development posture. The decision record konsolidat#90 defers a production Airbyte (Helm on Kubernetes, or a lighter scheduled runner) until the connector count decides between them.
Source configuration
spec.yaml:
| Setting | Required | Default | Notes |
|---|---|---|---|
tenant_id, client_id, client_secret | yes | - | Azure AD, stored as Airbyte secrets |
environment_url | yes | - | https://mycompany.operations.dynamics.com |
page_size | no | 5000 | OData page size, 100 to 10000 |
cross_company | no | true | Adds cross-company=true to every request so one sync covers every legal entity. Disable to read only the service principal's default company |
OData streams
The connector ships 14 streams (streams.py, source.py). Each lands in epm_raw.<stream name> with raw field passthrough plus Airbyte's _airbyte_raw_id and _airbyte_extracted_at.
| Stream (raw table) | OData entity | Mode | Primary key | Cursor |
|---|---|---|---|---|
general_journal_account_entry_bi_entities | GeneralJournalAccountEntryBiEntities | Incremental | SourceKey | SourceKey |
general_journal_entry_bi_entities | GeneralJournalEntryBiEntities | Incremental | SourceKey | SourceKey |
main_accounts | MainAccounts | Full refresh | MainAccountId | - |
main_account_categories | MainAccountCategories | Full refresh | ReferenceId | - |
legal_entities | LegalEntities | Full refresh | LegalEntityId | - |
ledgers | Ledgers | Full refresh | LegalEntityId | - |
fiscal_calendar_years | FiscalCalendarYears | Full refresh | none | - |
dimension_attributes | DimensionAttributes | Full refresh | DimensionName | - |
financial_dimension_values | FinancialDimensionValues | Full refresh | none | - |
exchange_rates | ExchangeRates | Incremental | - | StartDate |
exchange_rate_types | ExchangeRateTypes | Full refresh | Name | - |
budget_register_entries | BudgetRegisterEntries | Incremental | EntryNumber | Date |
consolidate_account_groups | ConsolidateAccountGroups | Full refresh | ConsolidationAccountGroup | - |
trial_balance_fiscal_year_snapshots | TrialBalanceFiscalYearSnapshots | Full refresh | none | - |
The GL streams read the BI entity views, which expose D365's internal RecId as SourceKey, a monotonic surrogate key. Posted GL is immutable in D365 (corrections post as new reversing rows with a higher SourceKey), so a SourceKey high-water mark captures every new row, including back-dated postings into open prior periods that an AccountingDate cursor would miss. Incremental streams send $filter=<cursor> ge <state> and advance the state per record.
Retries: a Retry-After header is honoured when present; 429 and 5xx responses are retried with backoff.
In Airbyte, enable all 14 streams. Use Incremental for the four streams with a cursor and Full refresh (overwrite) for the rest.
From raw rows to models
Set erp_sources in dbt_project/dbt_project.yml. It defaults to empty (konsolidat#207): no ERP adapter builds, and the trial-balance upload is the canonical source.
vars:
erp_sources: [] # default; set [d365_fo] to build the D365 adapter
Edit it to [d365_fo] and commit, or pass --vars '{erp_sources: [d365_fo]}' to a dbt command. This is a deliberate hand edit: konsol/dbt_config.py manages dimensions, base_measures and the fiscal vars, and leaves erp_sources alone, because a Connector being enabled says nothing about its data having landed (the whole build broke once when it was derived from connector state, konsolidat#139). Each stg_d365_fo__* model starts with config(enabled = 'd365_fo' in var('erp_sources', [])), and the canonical stg_* models UNION ALL one adapter per listed source.
Raw table (epm_raw) | Adapter | Canonical or bronze model |
|---|---|---|
general_journal_account_entry_bi_entities | stg_d365_fo__gl_entries | stg_gl_entries, then bronze_general_journal_account_entries |
general_journal_entry_bi_entities | stg_d365_fo__gl_journal_entries | bronze_general_journal_entries |
main_accounts, main_account_categories | stg_d365_fo__accounts, stg_d365_fo__main_account_categories | stg_accounts, bronze_main_accounts, bronze_main_account_categories |
legal_entities, ledgers | stg_d365_fo__legal_entities (joins ledgers for the currency) | stg_legal_entities, bronze_legal_entities |
fiscal_calendar_years | stg_d365_fo__fiscal_calendar_years, stg_d365_fo__fiscal_calendars, stg_d365_fo__fiscal_periods | stg_fiscal_periods, bronze_fiscal_calendar_years, bronze_fiscal_calendars |
dimension_attributes, financial_dimension_values | stg_d365_fo__financial_dimensions, stg_d365_fo__financial_dimension_values | bronze_financial_dimensions, bronze_financial_dimension_values |
exchange_rates, exchange_rate_types | stg_d365_fo__exchange_rates, stg_d365_fo__exchange_rate_types | stg_exchange_rates, bronze_exchange_rate_currency_pairs, bronze_exchange_rate_types |
budget_register_entries | stg_d365_fo__budget_entries, stg_d365_fo__budget_register_entries | stg_budget_entries, bronze_budget_transaction_lines, bronze_budget_register_entries |
consolidate_account_groups | stg_d365_fo__consolidation_groups | bronze_consolidation_account_groups |
trial_balance_fiscal_year_snapshots | stg_d365_fo__trial_balance | stg_trial_balance, bronze_trial_balance_snapshot |
Note that exchange rates from the ERP are not what consolidation translates at. The governed Group Exchange Rate documents in konsol are the one source of truth (epm_staging.group_exchange_rates); the ERP feed is only an input to "Pre-fill from ERP" on those documents.
The dbt source d365_raw declares freshness on the two GL tables: warn after 24 hours, error after 48 hours since _airbyte_extracted_at.
Running and scheduling syncs
| Approach | How |
|---|---|
| On demand | Pipeline Run in Desk, New, Run Pipeline. The Extracting phase triggers the Airbyte connection from EPM Settings or the Connector, then dbt builds. Tick skip_sync to build without extracting |
| Scheduled | A Pipeline Schedule (5-field cron) starts a Pipeline; evaluated every minute |
| Airbyte's own scheduler | Set a schedule on the connection in Airbyte; the webhook reports completion to konsol, and a Build Approval or a scheduled Pipeline Run then builds |
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
401 Unauthorized from D365 | Expired client secret, or the service principal is not registered under Microsoft Entra ID applications in D365 | Rotate the secret; register the client ID with a permitted user. Use Test Extract on the Connector |
| Empty sync | cross_company disabled, so only the default company is read | Enable extract_cross_company on the Connector and re-provision |
| Missing entities | The data entity is not exposed in D365 | Ask the D365 administrator |
Timeout or 429 on large syncs | Page size too large, or throttling | Lower extract_page_size; the stream retries with Retry-After |
Rows in epm_raw, nothing in staging | erp_sources does not list d365_fo | Set it in dbt_project.yml and rebuild |
Connector Health Stale or Never | The webhook is not configured, or the sync does not run | Configure the webhook and secret; check the Airbyte connection |
| Airbyte cannot reach ClickHouse | Destination host is a container name, or the kind node is not on open_epm | Use 172.30.0.10:8123; re-run scripts/setup-airbyte.sh |
Next steps
- ERPNext Integration: the other shipped adapter
- Initial Setup Guide: entities, chart, rates, connectors
- Configuration Reference: EPM Settings Airbyte fields
- Bronze Models