This repository contains a .NET console application that demonstrates how to connect to and query Microsoft Dataverse using OAuth authentication and the Dataverse Web API.
- .NET 6+ SDK
- Azure App Registration with Dataverse API permissions
- Practical OData query implementation against the standard Contacts DV table
-
Set up Azure App Registration:
- Register an application in Azure Portal
- Add API permission:
Dataverse API
→user_impersonation
- Create a client secret
-
Configure the application: Replace these placeholders in
Program.cs
:string tenantId = "YOUR_TENANT_ID"; // Azure AD Directory (tenant) ID string clientId = "YOUR_CLIENT_ID"; // Application (client) ID string clientSecret = "YOUR_CLIENT_SECRET"; // Client secret value string dataverseUrl = "YOUR_DATAVERSE_URL"; // e.g., https://yourorg.crm.dynamics.com/
- Store credentials securely (e.g., Azure Key Vault, environment variables)
- Never commit secrets to version control
- Follow principle of least privilege for API permissions
OAuth 2.0 authentication with MSAL (Microsoft.Identity.Client).
- Customizable API queries ($select, $top, $orderby).
- Structured JSON response parsing.
- Error handling for API failures.