Dynamics 365 WebAPI and C# – Configuring Sample Code

1 Comment

Microsoft has downloadable samples that demonstrate using the Dynamics 365 WebAPI with C#. The samples contain examples of using HttpClient getasync, sendasync with JSON.

The samples can be downloaded at https://code.msdn.microsoft.com/CRM-Web-API-Functions-and-a44416bb, with the code walkthrough at https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/web-api-functions-actions-sample-csharp.

In this post we will configure the code to run with Dynamics 365.

First, click to download:

You will see:

Open the solution in Visual Studio:

You will see:

In NuGet, click Restore in the top right:

Open the app.config file. In this post we will be running this code on Dynamics 365 (i.e. CRM Online). Rename the “default” key to “onprem, and the “CRMOnline” key to “default”. Enter your D365 credentials. Also, register an app on Azure and copy the Application Id into the Client Id field in the App.Config:

Note if you see the messages:

“The request body must contain the following parameter: ‘client_secret or client_assertion” or “The user or administrator has not consented to use the application with ID ‘*****’ named ‘*****’. Send an interactive authorization request for this user and resource”, ensure you are using the application id as the client id, and ensure delegated permissions in your Azure app as well as clicked Grant Permissions.

Your App.Config file should look like:

Build the solution and run. You will see output:

And records created in Dynamics 365.

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

One Response to Dynamics 365 WebAPI and C# – Configuring Sample Code

Leave a Reply

Your email address will not be published. Required fields are marked *