Picture
Dynamics 365 Customer Insights

Client libraries

This page has instructions on how to get started using the client libraries available for the Customer Insights API.

All library source code and sample applications can be found on the Customer Insights GitHub page:
https://github.com/microsoft/Dynamics365-CustomerInsights-Client-Libraries

For information on client library generation, check out our page on AutoRest.

All package locations:

NuGet (C#): https://www.nuget.org/packages/Microsoft.Dynamics.CustomerInsights.Api/

NPM (NodeJS): https://www.npmjs.com/package/@microsoft/customerinsights

PyPi (Python): https://pypi.org/project/customerinsights/

Sonatype/Maven (Java): TBD

C# NuGet

This section details how to get started using the C# client libraries from NuGet.org.

Picture

Package info

Information on the package can be found at this location: https://www.nuget.org/packages/Microsoft.Dynamics.CustomerInsights.Api/

Currently this package supports netstandard2.0netcoreapp2.0, and .NET Framework 4.5.2.

Picture

Adding to a C# project

In Visual Studio, enter the NuGet Package Manager for your project.

Search for Microsoft.Dynamics.CustomerInsights.Api.

Click Install to add the package to the project.

Alternatively, run this command in the NuGet Package Manager Console:

Install-Package -Id Microsoft.Dynamics.CustomerInsights.Api -Source nuget.org -ProjectName <project name> [-Version <version>]

Picture

Using the C# client library

To use the client library, first use the Microsoft Authentication Library (MSAL) to get an AccessToken using your existing App registration.

After successfully authenticating and acquiring a token, construct a new or use an existing HttpClient with the additional DefaultRequestHeaders "Authorization" set to "Bearer <access token>" and "Ocp-Apim-Subscription-Key" set to the subscription key from your Customer Insights environment.

Make sure to re-set the "Authorization" header when appropriate (i.e. when the token is expired).

Pass this HttpClient into the construction of the CustomerInsights client.

Make calls with the client to either the "extension methods" (e.g. GetAllInstancesAsync) or if access to the underlying Microsoft.Rest.HttpOperationResponse is wanted the "http message methods" (e.g. GetAllInstancesWithHttpMessagesAsync).

When the response comes back, it will likely be of type object because the method can return multiple types (e.g. IList<InstanceInfo> and ApiErrorResult). To check the return type, you can safely cast the objects into the response types specified on the Api Details page for that operation.

If more information on the request is needed, use the "http message methods" to access the raw response object.

Java Maven

Coming soon...