Xrm.Crm.WebApi
0.0.29
See the version list below for details.
dotnet add package Xrm.Crm.WebApi --version 0.0.29
NuGet\Install-Package Xrm.Crm.WebApi -Version 0.0.29
<PackageReference Include="Xrm.Crm.WebApi" Version="0.0.29" />
paket add Xrm.Crm.WebApi --version 0.0.29
#r "nuget: Xrm.Crm.WebApi, 0.0.29"
// Install Xrm.Crm.WebApi as a Cake Addin
#addin nuget:?package=Xrm.Crm.WebApi&version=0.0.29
// Install Xrm.Crm.WebApi as a Cake Tool
#tool nuget:?package=Xrm.Crm.WebApi&version=0.0.29
Xrm.Crm.WebApi
Xrm.Crm.WebApi is a library intended to simplify the use of the Microsoft Dynamics Crm REST API.
It was created out of necessity since the official SDK does not support dotnet core.
Getting started
Currently the library only supports the online version with the Server-to-server authentication.
The on-premisse authentication and the user authentication will be added in the future.
You can read more about the Server-to-server authentication and how to create a Dynamics 365 application user here.
Initializing the connection:
Guid clientId = new Guid("{00000000-0000-0000-0000-000000000000}");
string clientSecret = "";
string crmBaseUrl = "https://myOrg.crm.dynamics.com";
Guid tenantId = new Guid("{00000000-0000-0000-0000-000000000000}");
ServerToServerAuthentication authentication = new ServerToServerAuthentication(clientId,clientSecret, crmBaseUrl, tenantId);
WebApi webApi = new WebApi(authentication);
Basic CRUD
All the methos have a Async option.
Create
Basic Create
Entity contact = new Entity("contact");
contact["firstname"] = "Jose";
contact["gendercode"] = 1;
contact["isbackofficecustomer"] = false;
contact["overriddencreatedon"] = DateTime.Now.ToUniversalTime();
Guid contactId = webApi.Create(contact);
Lookup Properties
The library will add the necessary information if you use the 'EntityReference' object to define the relationship value
Entity contact = new Entity("contact");
contact["firstname"] = "Jose";
contact["accountid"] = new EntityReference("account", new Guid("{00000000-0000-0000-0000-000000000000}"));
Guid contactId = webApi.Create(contact);
The 'EntityReference' type also works with alternate keys
Entity contact = new Entity("contact");
contact["firstname"] = "Jose";
contact["accountid"] = new EntityReference("account", "my_key_name", "my_value");
Guid contactId = webApi.Create(contact);
You can also explicitly add the relationship
Entity contact = new Entity("contact");
contact["firstname"] = "Jose";
contact["accountid@odata.bind"] = "/accounts(00000000-0000-0000-0000-000000000000)";
Guid contactId = webApi.Create(contact);
Retrieve
Currently only 'FetchXml' has been tested and extensively validated when retrieving multiple records. Other options will be added/improved in the future.
Using FetchXml
string fetchXml = @"
<fetch count='100'>
<entity name='contact'>
<all-attributes />
</entity>
</fetch> ";
RetrieveMultipleResponse retrieveMultipleResponse = webApi.RetrieveMultiple(fetchXml);
List<Entity> entities = retrieveMultipleResponse.Entities;
foreach(Entity entity in entities)
{
string firstname = entity.GetAttributeValue<string>("firstname");
DateTime firstname = entity.GetAttributeValue<DateTime>("createdon");
EntityReference accountid = entity.GetAttributeValue<EntityReference>("accountid");
}
Single record
All attributes
Entity entity = webApi.Retrieve("contact", new Guid("00000000-0000-0000-0000-000000000000"));
Only 'firstname' and 'createdon' are selected in the API
Entity entity = webApi.Retrieve("contact", new Guid("00000000-0000-0000-0000-000000000000"), "firstname", "createdon");
Support for retrieving a single record using an alternate key will be added.
Update
The update method follows the same logic from the create method. The only difference is: the 'Entity' object needs to have a Id or a alternate key
Entity contact = new Entity("contact", new Guid("00000000-0000-0000-0000-000000000000"));
contact["firstname"] = "Jose";
webApi.Update(contact);
Entity contact = new Entity("contact", "my_key_name", "my_key_value");
contact["firstname"] = "Jose";
webApi.Update(contact);
Upsert
The upsert method is identical to the Update. You can control its behavior with the 'InsertOptions' parameter. The default option will update the record if it already exists or create it it doesn't
Entity contact = new Entity("contact", new Guid("00000000-0000-0000-0000-000000000000"));
contact["firstname"] = "Jose";
webApi.Upsert(contact);
Delete
To delete a entity you only need to provide the logical name, id or alternate key
Entity contact = new Entity("contact", new Guid("00000000-0000-0000-0000-000000000000"));
webApi.Delete(contact);
Entity contact = new Entity("contact", "my_key_name", "my_key_value");
webApi.Delete(contact);
Todos
- Improve the Docs
- Improve the Todos 😊
License
Free Software, Hell Yeah!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 11.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-preview1 | 26,671 | 11/26/2019 |
0.0.29 | 5,535 | 6/6/2019 |
0.0.28 | 652 | 4/8/2019 |
0.0.25 | 713 | 2/6/2019 |