Azure Functions for Dynamics 365 integrations
By Emil Björk · Microsoft business apps consultant, Gothenburg
How to use Azure Functions to extend and integrate Dynamics 365 — patterns, authentication, lifecycle, performance, and the trade-offs vs Power Automate.
On this page (3)
When low-code (Power Automate, Logic Apps) doesn't fit, Azure Functions are the next-step compute platform for Dynamics 365 integrations and extensions. They're code (typically C#, JavaScript, Python, PowerShell), they run on demand without server management, and they integrate cleanly with the broader Azure and Microsoft cloud ecosystem.
When to reach for Azure Functions.
- Complex transformations that Power Automate can't express cleanly — recursive logic, complex string parsing, integration with libraries.
- High-throughput scenarios where Power Automate's per-action cost or throughput doesn't fit.
- Custom connectors beyond what platform connectors provide.
- Webhook receivers for external systems pushing events.
- Scheduled batch jobs that need substantial compute.
- Background workers consuming Service Bus / queue messages.
- API façades in front of Dataverse for partner consumption.
Triggers
Functions are triggered by events:
- HTTP — function exposed at a URL; called via REST. The most common for integration scenarios.
- Timer — runs on a schedule. Replaces "Scheduled Tasks" running in legacy infrastructure.
- Queue / Service Bus — runs when a message arrives. Used for asynchronous processing of events from Dataverse.
- Event Grid — runs on Event Grid events.
- Blob Storage — runs when a blob is created or modified.
- Cosmos DB — runs on document changes.
For Dynamics 365 integrations:
- HTTP-triggered functions receive webhook calls from Dataverse, Business Central, or external systems.
- Service Bus-triggered functions consume events from Dataverse's Service Bus integration.
- Timer-triggered functions run periodic exports / imports.
Authentication.
To call Dataverse from a Function:
- Microsoft Entra ID app registration — the Function authenticates as a service principal.
- Managed Identity — if the Function is hosted in Azure, use Azure Managed Identity for credential-free authentication to Dataverse.
- OAuth 2.0 client credentials flow — exchange client ID + secret for access token; use token in Dataverse API calls.
The Dataverse SDK for .NET handles this in straightforward code; for other languages, use HTTP client libraries with appropriate token handling.
Calling Dataverse from a Function.
// C# example using Dataverse SDK
var serviceClient = new ServiceClient(
new Uri("https://contoso.crm.dynamics.com"),
clientId,
clientSecret,
true);
var customer = await serviceClient.RetrieveAsync(
"account",
new Guid("..."),
new ColumnSet("name", "telephone1"));
Receiving webhook from Dataverse.
[FunctionName("DataverseWebhook")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req,
ILogger log)
{
var body = await new StreamReader(req.Body).ReadToEndAsync();
// body contains Dataverse's notification payload
// Process the change
return new OkResult();
}
The function URL is registered as a webhook subscription target in Dataverse.
Hosting plans
Azure Functions have multiple hosting tiers:
- Consumption — pay-per-execution; auto-scale to zero; cold starts. Good for low-volume / sporadic workloads.
- Premium — pre-warmed instances; no cold starts; VNET integration. Good for production with consistent traffic.
- Dedicated (App Service Plan) — like running on a regular App Service; predictable cost; no per-execution scaling. Good for very high or very steady workloads.
For most Dynamics 365 integration scenarios, Consumption or Premium is appropriate.
Performance.
- Cold starts — Consumption Functions starting from idle take 1-5 seconds. Premium pre-warmed instances eliminate.
- Concurrent execution — Functions scale automatically; many concurrent executions of the same function are normal.
- Throttling — Dataverse has API rate limits; high-throughput Functions need to handle 429 responses with exponential backoff.
Monitoring.
- Application Insights integration — automatic for Functions. Trace messages, exception logs, performance metrics, request rates.
- Function execution history — visible in the Azure portal.
- Custom telemetry — log structured events for richer analysis.
Patterns and examples.
- Webhook-to-record-update — Dataverse changes notify a webhook; Function processes and updates external system.
- Periodic data sync — Timer-triggered Function pulls from external API and writes to Dataverse.
- Event-driven processor — Service Bus-triggered Function consumes events; processes; writes results back.
- API façade — HTTP-triggered Function exposes a curated API in front of Dataverse for partner consumption.
- Validation service — Function called from a Power Automate flow; validates complex business rules; returns yes/no.
Cost.
- Consumption — free up to a generous tier, then very inexpensive per execution. Most Dynamics 365 integration scenarios run in the cheap zone.
- Premium / Dedicated — fixed monthly cost; predictable.
Limits.
- Function execution time — Consumption limits at 5–10 minutes; Premium / Dedicated can be longer.
- Memory — Consumption ~1.5GB; Premium more.
- Connections — outbound connection limits per Function App.
Common pitfalls.
- Long-running operations — Functions aren't for hours-long work; use Durable Functions or Logic Apps.
- Cold start in user-facing scenarios — Consumption cold starts can frustrate; use Premium.
- No structured logging — debugging without proper logs is brutal.
- Hard-coded credentials — store in Azure Key Vault.
Operational reality
Azure Functions are the workhorse for code-grade Dynamics 365 integration. Choose them when low-code tools don't fit; use the platform features (App Insights, Key Vault, Managed Identity) consistently; treat each Function App as a proper production deployment with CI/CD, monitoring, and ALM.
Further reading
Related guides
- Azure Data Factory with Dynamics 365How to use Azure Data Factory for Dynamics 365 data integration — connectors, common patterns, performance tuning.
- Azure Service Bus integration with DataverseHow Dataverse publishes change events to Azure Service Bus — registration, message format, queues vs topics, and resilient consumer patterns.
- Azure Synapse Link for DataverseHow Synapse Link replicates Dataverse data to Azure Data Lake Storage continuously — architecture, configuration, query patterns.
- Microsoft Fabric and Dynamics 365How Microsoft Fabric and OneLake change Dynamics 365 analytics — Synapse Link, lakehouses, and the migration from Export to Data Lake.
- Logic Apps Standard vs ConsumptionThe two Logic Apps hosting models — Standard (single-tenant) vs Consumption (multi-tenant) — and how to choose between them for Dynamics 365 integrations.
Browse every guide in Integrations or just Azure services.
Was this helpful?
Signals which guides land and which need work. No account, no comment box — corrections go through the contact page.
Spot something wrong or want a topic covered? Send a correction or a topic request — both are welcome.