How to – “Register a New WebHook” through Plugin Registration Tool in Dynamics 365


With July 2017 Update, now we have the option to register a new Webhook through Plugin Registration tool.

Download the latest Plugin Registration Tool from NuGet using the PowerShell script à

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/download-tools-nuget

Through registering a Webhook, we can send data (execution context) about any operation performed on Dynamics 365 to the external services or application. The execution context information is passed in JSON format here.

More details here

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/use-webhooks

Let us take a simple scenario to see it in action.

First will create an Azure Webhook which passes the Execution Context to the Azure Service Bus Queue. We will also create a sample Queue Listener application that parses and reads the information from the queue.

  • Create a new Function of type Webhook + API (CSharp).

  • Select Integrate in the newly created function and click on New Output button and add Azure Service Bus as an output.

  • Specify Message type as Service Bus Queue and other required values like Service Bus Connection, Queue Name and the parameter name and click on Save.
  • Update the code for our function to pass the execution context information to the queue
  • Now let us register our Webhook inside Dynamics 365. For this copy the function URL using Get function URL button.


  • Click on Copy.

  • Inside Plugin Registration tool, click on Register à Register New Web Hook.

  • Specify any Name for the Webhook. In the Endpoint URL, paste the URL copied without any query string part. For Authentication select WebhookKey and paste the “code” query string value to register the Webhook.

  • Register a new step of Lead Create to it.

  • After registering the step, to test our Webhook Function, let us create a new lead record inside Dynamics 365.

  • Back in our function, click on Monitor to check the log. There we can see the execution context information passed to our function.

  • Inside the Queue specified as Output of the function, we can see the new messages added.

  • Below is the sample code to read the message from the queue.

</p>
<p>private static void QueueClientExample()<br />
{<br />
// create a new Shared Access Policy for the queue<br />
// set the connection string of the Shared Access Policy created<br />
var connectionString = "Endpoint=sb://[namespace].servicebus.windows.net/;SharedAccessKeyName=MyPolicy;SharedAccessKey=[KeyValue];EntityPath=mycrmqueue";</p>
<p>// create the Queue Client object<br />
var client = QueueClient.CreateFromConnectionString(connectionString);</p>
<p>// get the message from the Queue Client<br />
BrokeredMessage brokeredMessage = client.Receive();</p>
<p>var stream = brokeredMessage.GetBody&lt;Stream&gt;();<br />
StreamReader streamReader = new StreamReader(stream);<br />
string jsonData = streamReader.ReadToEnd();<br />
jsonData = jsonData.Replace(@"\", string.Empty).Trim(new char[] { '\"' });<br />
JObject context = JObject.Parse(jsonData);</p>
<p>Console.WriteLine("Primary Entity Name = " + context["PrimaryEntityName"] + " Message Name = " + context["MessageName"]);</p>
<p>}</p>
<p>

  • The output

More on Azure Functions à

https://nishantrana.me/category/azure-functions/

Similar example using Azure Service Bus Integration à

https://nishantrana.me/2017/03/22/configure-dynamics-365-and-azure-service-bus-integration-through-queue-and-queueclient/

Hope it helps..

Advertisements

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

5 thoughts on “How to – “Register a New WebHook” through Plugin Registration Tool in Dynamics 365”

  1. Hi Nishant, thanks for this post.

    Just wondering what are the benefits using Webhooks + Azure Functions, instead of using just Service Endpoints in CRM (sending the execution context to a queue/topic in the Service Bus)? Is not the same thing just with extra steps?

    Like

  2. Good question. This nicely explains it Felipe

    When deciding between the webhook model and the Azure Service Bus integration, here are some items to keep in mind:

    Azure Service Bus works for high scale processing, and provides a full queueing mechanism if Dynamics 365 is pushing many events.
    Webhooks can only scale to the point at which your hosted web service can handle the messages.
    Webhooks enables synchronous and asynchronous steps. Azure Service Bus only allows for asynchronous steps.
    Webhooks send POST requests with JSON payload and can be consumed by any programming language or web application hosted anywhere.
    Both webhooks and Azure Service Bus can be invoked from a plugin or custom workflow activity.

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/use-webhooks

    Like

  3. Hello Nishant

    What is the method of receiving response back to the CRM plugin or workflow? I am working on a scenario where I sent the plugin context to the function but I would expect the response of the function will set entity attributes in return. Can you guide me how this can be done?

    Like

  4. Hi

    Interesting post as web hook endpoint can also be used to trigger an MS Power Automate flow.
    However, as for any service endpoint I am wondering how you deploy this stuff.
    The service endpoint url seems to be part of the deployment, but in DTAP scenario also the endpoint will differ per type of environment?

    Kind regards

    Kim

    Like

Leave a Reply to Jandost Khoso Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Welcome to the Blog & Website of Paul Andrew

Technical Leadership Centred Around the Microsoft Data Platform

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Dynamics 365 Ninja!

CRM for You and Me

Customer Relationship Mgt App for the Professional

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Knowhere365

Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM

EVOLVED365

Step into the world of a Dynamics 365 Consultant

Dianamics PCF Lady

Diana & Dynamics 365 & Power Platform

Sara Lagerquist

No Code Customization Concepts

innovativeaj

developer, designer, writer, fun loving, patriotic, humble and a sweet person inside out :) love and respect people who have a great sense of humor.

Temmy Wahyu Raharjo

dreaming to be a clean coder and TDD minded programmer.

%d bloggers like this: