Skip to main content

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​

  1. An Azure app registration gives the connector a service principal with application permissions on D365.
  2. A Connector document in konsol (Desk, module Pipeline) holds the credentials, the legal entities served, and the Airbyte connection id.
  3. Airbyte runs the source-d365-fno connector and lands raw rows in ClickHouse database epm_raw, one table per stream.
  4. dbt adapter models stg_d365_fo__* map the raw rows to the canonical staging schema. They build only when d365_fo is listed in the dbt var erp_sources.
  5. Bronze, silver and gold read the canonical models and never an ERP table.

Azure AD app registration​

  1. Open Azure Portal, App registrations and click New registration. Name: Konsolidat Airbyte. Single tenant. No redirect URI.
  2. Note the Application (client) ID and Directory (tenant) ID.
  3. Under Certificates & secrets, create a client secret and copy the value at once; it is shown only once.
  4. Under API permissions, add Dynamics ERP (Dynamics 365 Finance and Operations), choose Application permissions, pick the access role your tenant exposes (for example Connector.FullAccess or AX.FullAccess), and Grant admin consent.
  5. 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.

ValueWhere to find itWhere it goes
Tenant IDApp registration, OverviewConnector tenant_id
Client IDApp registration, OverviewConnector extract_client_id
Client secretCertificates & secretsConnector extract_client_secret
Environment URLD365, System administration; looks like https://yourorg.operations.dynamics.comConnector 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).

TabFieldNotes
Connectorconnector_name, erp_type = d365_fo, enableddbt_adapter_prefix (stg_d365_fo) and airbyte_source are derived
Connectorairbyte_source_id, airbyte_connection_idFilled by Test & Provision Airbyte, or pasted from the Airbyte UI
Connectorsync_frequency_minutes (default 1440)Threshold for the Stale health status
Extract Credentialstenant_id, environment_url, extract_client_id, extract_client_secretShown for d365_fo and d365_bc
Extract Optionsextract_page_size (default 100), extract_cross_company (default on)Passed to the Airbyte source as page_size and cross_company
Write-Back Credentialswriteback_enabled, optional separate credentials, writeback_fiscal_year_start_monthBudget write-back to BudgetRegisterEntries
Legal EntitiesConnector Legal Entity rows (entity_id, entity_name)Which entities this connector serves; scopes connector health
Dimension MappingsConnector 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 Settings airbyte_api_url, airbyte_client_id, airbyte_client_secret, airbyte_workspace_id, airbyte_destination_id and airbyte_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 settingValue
TypeClickHouse
Host172.30.0.10 (pinned on the open_epm network; EPM Settings airbyte_clickhouse_host)
Port8123 (the container port, whatever CLICKHOUSE_HTTP_PORT is)
Databaseepm_raw (EPM Settings airbyte_clickhouse_database)
User, passwordCLICKHOUSE_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:

SettingRequiredDefaultNotes
tenant_id, client_id, client_secretyes-Azure AD, stored as Airbyte secrets
environment_urlyes-https://mycompany.operations.dynamics.com
page_sizeno5000OData page size, 100 to 10000
cross_companynotrueAdds 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 entityModePrimary keyCursor
general_journal_account_entry_bi_entitiesGeneralJournalAccountEntryBiEntitiesIncrementalSourceKeySourceKey
general_journal_entry_bi_entitiesGeneralJournalEntryBiEntitiesIncrementalSourceKeySourceKey
main_accountsMainAccountsFull refreshMainAccountId-
main_account_categoriesMainAccountCategoriesFull refreshReferenceId-
legal_entitiesLegalEntitiesFull refreshLegalEntityId-
ledgersLedgersFull refreshLegalEntityId-
fiscal_calendar_yearsFiscalCalendarYearsFull refreshnone-
dimension_attributesDimensionAttributesFull refreshDimensionName-
financial_dimension_valuesFinancialDimensionValuesFull refreshnone-
exchange_ratesExchangeRatesIncremental-StartDate
exchange_rate_typesExchangeRateTypesFull refreshName-
budget_register_entriesBudgetRegisterEntriesIncrementalEntryNumberDate
consolidate_account_groupsConsolidateAccountGroupsFull refreshConsolidationAccountGroup-
trial_balance_fiscal_year_snapshotsTrialBalanceFiscalYearSnapshotsFull refreshnone-

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)AdapterCanonical or bronze model
general_journal_account_entry_bi_entitiesstg_d365_fo__gl_entriesstg_gl_entries, then bronze_general_journal_account_entries
general_journal_entry_bi_entitiesstg_d365_fo__gl_journal_entriesbronze_general_journal_entries
main_accounts, main_account_categoriesstg_d365_fo__accounts, stg_d365_fo__main_account_categoriesstg_accounts, bronze_main_accounts, bronze_main_account_categories
legal_entities, ledgersstg_d365_fo__legal_entities (joins ledgers for the currency)stg_legal_entities, bronze_legal_entities
fiscal_calendar_yearsstg_d365_fo__fiscal_calendar_years, stg_d365_fo__fiscal_calendars, stg_d365_fo__fiscal_periodsstg_fiscal_periods, bronze_fiscal_calendar_years, bronze_fiscal_calendars
dimension_attributes, financial_dimension_valuesstg_d365_fo__financial_dimensions, stg_d365_fo__financial_dimension_valuesbronze_financial_dimensions, bronze_financial_dimension_values
exchange_rates, exchange_rate_typesstg_d365_fo__exchange_rates, stg_d365_fo__exchange_rate_typesstg_exchange_rates, bronze_exchange_rate_currency_pairs, bronze_exchange_rate_types
budget_register_entriesstg_d365_fo__budget_entries, stg_d365_fo__budget_register_entriesstg_budget_entries, bronze_budget_transaction_lines, bronze_budget_register_entries
consolidate_account_groupsstg_d365_fo__consolidation_groupsbronze_consolidation_account_groups
trial_balance_fiscal_year_snapshotsstg_d365_fo__trial_balancestg_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​

ApproachHow
On demandPipeline 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
ScheduledA Pipeline Schedule (5-field cron) starts a Pipeline; evaluated every minute
Airbyte's own schedulerSet 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​

IssueCauseFix
401 Unauthorized from D365Expired client secret, or the service principal is not registered under Microsoft Entra ID applications in D365Rotate the secret; register the client ID with a permitted user. Use Test Extract on the Connector
Empty synccross_company disabled, so only the default company is readEnable extract_cross_company on the Connector and re-provision
Missing entitiesThe data entity is not exposed in D365Ask the D365 administrator
Timeout or 429 on large syncsPage size too large, or throttlingLower extract_page_size; the stream retries with Retry-After
Rows in epm_raw, nothing in stagingerp_sources does not list d365_foSet it in dbt_project.yml and rebuild
Connector Health Stale or NeverThe webhook is not configured, or the sync does not runConfigure the webhook and secret; check the Airbyte connection
Airbyte cannot reach ClickHouseDestination host is a container name, or the kind node is not on open_epmUse 172.30.0.10:8123; re-run scripts/setup-airbyte.sh

Next steps​