Dynamics 365 CE integration with Shopify using Webhook

Introduction

In a previous article, we delved into valuable resources and integration options for Dynamics 365 CE and Shopify. Today, we will discuss integration process utilizing Shopify Webhook and Azure Function.

Details

As we are going to discuss approaches for integration using Webhook and Azure function so, let’s first understand what Webhook and Azure Function is.

Webhook

Webhook is based on the event-driven architecture, so we can understand webhook as a communication mechanism that allows one system to send real-time data to another system as soon as a specific event occurs. Acting as a trigger-based notification system, webhooks enable seamless integration between applications by instantly conveying information without the need for constant polling. This technology is widely used in modern web development, providing a more efficient and responsive way for systems to communicate and stay synchronized.

Shopify provides different Webhook that we can register for our app. You can refer to the documentation for the Shopify Webhook here. Under app settings, we can see different available Webhook.

Azure Function

To use Shopify Webhook we need a listener, which can receive data from Shopify and pass it to Dynamics 365 CE. One possible option to develop listener using Azure Function. Azure function is a serverless compute service that allows developers to build, deploy, and scale applications without the need to manage infrastructure. With Azure Functions, you can execute code in response to various events, such as HTTP requests, database changes, or messages from Azure Service Bus. This serverless computing model enables a pay-as-you-go approach, where you only pay for the resources your functions consume during execution. Azure Functions supports multiple programming languages, making it versatile for a wide range of application scenarios, from simple scripts to complex microservices architectures. It’s a powerful tool for creating scalable and event-driven solutions in the cloud.

Using HTTP Azure Function we can build a listener and register it under the Webhook.

namespace ShopifyListenerDemo
{
    public static class CustomerListener
    {
        [FunctionName("ShopifyHTTPListener")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
 
            string name = req.Query["name"];
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            Customer customer = JsonConvert.DeserializeObject<Customer>(requestBody );
            CRMHelper cRMHelper = new CRMHelper();
            cRMHelper.CustomerUpsert(customer, log);
 
            return new OkObjectResult("This HTTP triggered function executed successfully");
        }
    }
}

In the above sample code, I have a customer class that represents all the possible properties of the customer table, and I created a helper class that is responsible for connecting to Dynamics 365 CE and creating customer upsert customer records into Dynamics 365 CE.

Once we have deployed Azure Function, we can get the Function URL and register as a listener under the notification like below:

As soon as the customer is created, our Azure Function will trigger, and we can read data from requests and create customer records in Dynamics 365.

Summary

In this post, we discussed a strategic approach that leverages the power of Webhooks to create a robust connection between Dynamics 365 CE and Shopify. Similar to that, we can build this integration for other data synchronization requirements as well.

I hope it will help someone !!

Keep learning and Keep Sharing !!


Similar Articles
HIMBAP
We are expert in Microsoft Power Platform.