TeamHiPo.Dynamics.WebApi 1.0.6

There is a newer version of this package available.
See the version list below for details.
Install-Package TeamHiPo.Dynamics.WebApi -Version 1.0.6
dotnet add package TeamHiPo.Dynamics.WebApi --version 1.0.6
<PackageReference Include="TeamHiPo.Dynamics.WebApi" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TeamHiPo.Dynamics.WebApi --version 1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TeamHiPo.Dynamics.WebApi, 1.0.6"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install TeamHiPo.Dynamics.WebApi as a Cake Addin
#addin nuget:?package=TeamHiPo.Dynamics.WebApi&version=1.0.6

// Install TeamHiPo.Dynamics.WebApi as a Cake Tool
#tool nuget:?package=TeamHiPo.Dynamics.WebApi&version=1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Simple Query with results

Step 1:

Create a class to hold the entity data you want. For example a contact.

        public class Contact : BaseEntity
            public string FullName { get; set; }
            public string FirstName { get; set; }
            public string ContactId { get; set; }

Use the "DynamicsEntity" attribute on the class and extend the BaseEntity class to get some static helpers for use later in the example. Also use the "DynamicsIncludeInQuery" attribute to flag properties that you wanted included in the result set. Use the NewtonSoft "JsonProperty" attributes to tell the parser what name to expect in the json for this property. The BaseEntity helper functions will use these attributes to process results for its functions. Finally use the "DynamicsId" attribute to indicate which field is the Id field for this entity.

Step 2:

Create the D365WebService class passing it settings for which environment you want to connect to:

         D365WebService service = new D365WebService(Settings);

An instance of the DynamicsConnectionSettings class is passed into the constructor of the D365WebService to create it. The connection and DynmaicsConnectionSettings class assume that server to server authentication is being used. The following link provides instructions on how to create a AppId and Password for server to server authentication.

Step 3:

Create a query as follows:

        //create a new QueryFilter object
        QueryFilter filter = new QueryFilter();
        //Add filter criteria using the AddCriteria method
        //in this example a string is used for the field name. The base class static helpers can also be used as follows
        //so a string need not be used. For example Contact.GetSchemaName<Contact>(nameof(Contact.OwnerId))                 

        filter.AddCriteria("_ownerid_value", ComparisonOperators.Equal, "45AAEF1C-68AA-E711-A94E-000D3AF3538A");

        //create a retrieve multiple request and provide the entity name, fields and filter
        //if no filter is provided then all records are returned
        //notice the static help functions provided by the base class are used to get the entity name and list of fields
        //Alternately you can provide a list of fields to retrieve ad hoc as follows:
        //Fields = new SelectFieldList(new string[] {"fullname"})
        D365RetreiveMultipleRequest request = new D365RetreiveMultipleRequest()
            EntityName = Contact.GetEntityName<Contact>(),
            Fields = Contact.GetSelectFields<Contact>(),
            Filter = filter,
            //optional if this is not 0 then it will limit the amount of records returned
            RetrieveTop = 2
        //optionally you can set the sort order of the results
        request.AddOrderBy("firstname", ResultsOrder.Descending);
        //optionally you can include the record count. If not included the Count property will be null
        request.IncludeCount = true;

        D365ServiceResponse response = null;

        //Useful for debugging. The operation property is query component of the API request URL represented by the      retrieve  multiple request
        //from the above code
        Console.WriteLine($"Operation: {request.Operation}");
        //pass the request to the service
        response = service.RetreiveMultipleAsync(request).Result;

        //check for success
        if (response.Success)
            List<Contact> contacts = null;
            //get the list of contacts returned from the response by using the generic GetData method
            contacts = response.GetData<List<Contact>>();
            //for debug the Json returned by Dynamics 365 is in the Json property
            Console.WriteLine($"Count: {response.Count}");
            if (contacts.Count > 0)
                Console.WriteLine($"Id: {contacts.First().Id}");
                //the BaseEntity provides a property to get the URL of the Form for this record
                Console.WriteLine($"Relative Url: {contacts.First().RelativeUrl}");

To create a record

        Contact contact = new Contact()
            FirstName = "Fred",
            LastName = "Flintstone"
        D365WebService service = new D365WebService(Settings);

        D365CreateResponse response = service.CreateAsync(contact).Result;
        if (response.Success)
            Console.WriteLine($"RecordId: {response.Id}");

You may want to leave out some fields from the create message if they are null. Use the following:

        public class Contact : BaseEntity
             [JsonProperty("fullname", NullValueHandling = NullValueHandling.Ignore)]
             public string FullName { get; set; }

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.20 565 10/11/2018
1.0.19 504 9/19/2018
1.0.18 537 9/19/2018
1.0.17 510 9/19/2018
1.0.16 608 9/4/2018
1.0.14 576 8/31/2018
1.0.13 574 8/31/2018
1.0.12 653 7/12/2018
1.0.11 696 6/7/2018
1.0.10 622 6/7/2018
1.0.9 735 6/5/2018
1.0.8 655 6/5/2018
1.0.7 640 5/10/2018
1.0.6 701 5/1/2018
1.0.5 764 5/1/2018
1.0.4 675 4/30/2018
1.0.3 577 4/30/2018
1.0.2 707 4/30/2018
1.0.1 695 4/30/2018
1.0.0 731 4/30/2018