How to Integrate Dynamics 365 with Third-Party APIs Using Azure Functions
I have seen how difficult it can be when businesses depend on multiple platforms that do not communicate well. Dynamics 365 is strong by itself, but in most cases, it needs to connect with other services such as billing systems, shipping providers, or marketing tools. When those systems are disconnected, information stays in silos. Teams spend too much time entering data manually, customers experience delays, and leaders often work with outdated information.
To solve this, I prefer using Azure Functions. It is a serverless option that allows you to build lightweight pieces of code that run only when triggered. This approach keeps costs low while making sure Dynamics 365 communicates with third-party APIs in real time. The outcome is a connected setup where operations flow smoothly, data remains accurate, and business growth is supported without heavy custom development.
Basics of API Integration
Before getting into the steps, it is important to understand what API integration means. An API works as a connector that lets two different applications share data automatically. When Dynamics 365 is integrated with third-party APIs, it removes the need for manual updates and ensures that data flows seamlessly across platforms. Azure Functions sits in the middle as the bridge, handling the exchanges in a simple and flexible way.
In the previous blog, I explained why Dynamics 365 integration is valuable and how it improves efficiency, lowers costs, and provides real-time insights. That article focused on the benefits, while this one explains the practical process to set it up with Azure Functions. Together, they provide both the reasons for integration and the technical steps needed to achieve it.
Step 1: Register an Application for Authentication
Before Azure Functions can talk to Dynamics 365, we need to set up secure access. This is done by registering an app in Azure Active Directory (Azure AD).
- Go to the Azure Portal.
- In the search bar, type App registrations and click on it.
- Click New registration.
- Name: Enter something simple like Dynamics365IntegrationApp.
- Supported account types: Choose Accounts in this organizational directory only (recommended for most cases).
- Redirect URI: Leave blank unless you are using OAuth flows that need a return URL.
- Click Register.
Once created:
- Copy the Application (client) ID and Directory (tenant) ID.
- Under the left side panel, select Manage → Certificates & Secrets.
- Create a new Client Secret and copy it somewhere safe.
eb9f07e0-c483-4f2a-a789-fd9a8583abfe
- Under API Permissions, add Dynamics 365 (Dataverse) → user_impersonation.
This ensures your Azure Function can securely connect to Dynamics 365.
Step 2: Create an Azure Function App
Azure Functions will act as the “bridge” between Dynamics 365 and the external API.
- In the Azure Portal, search for Function App and click Create.
- Fill in the details:
- Subscription: Choose your Azure subscription.
- Resource Group: Create a new one or use an existing one.
- Function App name: e.g., d365-api-connector.
- Runtime stack: Choose the language you are comfortable with. Beginners often use .NET (C#) or Node.js (JavaScript).
- Region: Select the same region as your Dynamics 365 environment.
- Plan type: Select Consumption (Serverless) to pay only when the function runs.
- Storage account: Create one if needed.
- Subscription: Choose your Azure subscription.
- Click Review + Create, then Create.
Now you have an environment to write your integration code.
Step 3: Write the Function Code
Inside the Function App, create a new function with an HTTP trigger. This makes it run whenever a request is sent to its URL.
Basic flow of the code:
- Use your client ID, tenant ID, and client secret to request a token from Azure AD.
- Call the third-party API using this function.
- Process the response and return it back.
Example (simplified C#):
| [FunctionName(“CallThirdPartyAPI”)] public static async Task Run( [HttpTrigger(AuthorizationLevel.Function, “post”)] HttpRequest req, ILogger log) { // 1. Get data from Dynamics request string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); // 2. Call external API (example: GET request) using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY"); var response = await client.GetAsync("https://api.thirdparty.com/data"); var result = await response.Content.ReadAsStringAsync(); // 3. Return response return new OkObjectResult(result); }} |
Step 4: Link Dynamics 365 with Azure Function
Now connect Dynamics 365 to the Function so it runs when something happens, like creating a record.
Options:
- Webhooks: Easiest method for beginners. Configure a webhook in Dataverse that triggers the Function whenever a record is created or updated.
- Plugins: Write custom code in Dynamics 365 that calls the Function.
For webhooks:
- Open Power Platform Admin Center → choose your environment.
- Go to Settings → Webhooks.
- Create a new webhook pointing to your Function’s URL.
- Attach it to the event you want (e.g., when a new Contact is created).
This ensures Dynamics and the external API stay in sync automatically.
Step 5: Test the Integration
Testing helps confirm everything works as expected.
- Create or update a record in Dynamics 365.
- Check if the Function receives the request.
- Verify the external API is called correctly.
- Make sure the response flows back into Dynamics 365.
- Use Application Insights to check logs and debug any issues.
Step 6: Secure and Monitor
When moving to production, apply these safety and monitoring steps:
- Store API keys and secrets in Azure Key Vault.
- Use Azure API Management to control authentication, rate limiting, and logging.
- Monitor performance and failures with Azure Monitor dashboards.
- Add retry logic to your function to handle temporary errors.

These measures keep your integration stable and secure over time.
Conclusion
By following these steps, you can connect Dynamics 365 with almost any external service in a secure and reliable way. The process starts with registering the app in Azure AD, then creating a Function App to handle the logic, writing code to call the external API, and linking Dynamics 365 through webhooks or plugins. Once it is tested, secured, and monitored, the setup runs smoothly without heavy effort. I have seen this method help businesses cut down on manual work, keep systems in sync, and scale easily as they grow.
