Triggering Scheduled Azure WebJobs via a Dynamics 365 Web Hook

Jared Johnson, 06 April 2018

Web Hooks were introduced in Dynamics 365 V9. In the documentation for Web hooks, it is recommended to use them with Azure Functions, but what if you have existing Azure WebJobs? For example, WebJobs that are designed as a scheduled service to run complex rollup calculations on recently updated records. With the new Webhooks, you can trigger this straight away when a new record is created instead of having to wait for the schedule. I will demonstrate how to achieve this below.

First, we want to get the WebJobs Web hook URL and the credentials from the Properties of the WebJob in the Azure portal.

image

Once we have the credentials, we then need to create our authentication header value. To authenticate with the Azure WebJob we are going to use Basic Authentication. For this we first need to have our credentials separated by a colon and then Base64 encode the result. I use the online encoder at https://codebeautify.org/base64-encode to do this.

image

Then to register the CRM Web Hook we go to Register => Register New Web Hook in the Plugin Registration tool.

image

This will open the Web Hook Registration screen. On this screen we want to add the Web Jobs Web Hook URL into the Endpoint URL field, and set the Authentication drop-down to HttpHeader.  This will display a table where we can add the Http Headers we require. We want to click Add Property and set Authentication as the Key value, and then Basic followed by our base64 encoded credentials.

image

After saving, we can then register steps against the Web Hook just like creating steps for a plugin. For this example, I will create a step on Create of contact.

image

Now after creating a contact, we can refresh the Web Jobs page and see that it has successfully triggered the Web Job.

image