Dynamics 365 WebApi Toolkit library for .Net.
Currently, support only on-premise with AD authentication.
Add connection string with a name "Crm".
// appsettings.json
"ConnectionStrings": {
"Crm": "Url=https://host.local;Username=;Password=;Domain=DMNAME;Authtype=AD"
}
ConfigureServices.
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
...
services.AddCrmWebApiClient();
...
}
Inject ICrmWebApiClient into ApiController or another class
// AccountController.cs
...
using System.Threading.Tasks;
using CrmNx.Xrm.Toolkit;
using CrmNx.Xrm.Toolkit.Query;
...
[ApiController]
public class AccountController : ControllerBase
{
private readonly ICrmWebApiClient _crmClient;
public AccountController(ICrmWebApiClient crmClient)
{
_crmClient = crmClient ?? throw new ArgumentNullException(nameof(crmClient));
}
[HttpGet]
public async Task<IActionResult> GetAccounts(CancellationToken cancellationToken)
{
// await _crmClient.RetrieveMultipleAsync("account") - Retrieved all fields
var collection = await _crmClient.RetrieveMultipleAsync("account", QueryOptions.Select("fullname"), cancellationToken);
return Ok(collection.Entities);
}
}