K Khan
Oct 24, 2017
(4 votes)

EPiServer integration with azure logic apps(part 1)

Microsoft Logic Apps provide a way to simplify and implement scalable integrations and workflows in the cloud. There are three major components that we will need to understand to before start working.

  1. Designer - It is relevantly independent module built in ReactJS to design workflows in Visual Studio, or in the Azure portal. Prepares workflow data model in JSON for us.
  2. Logic App Runtime - Responsible to run all the tasks retrieved from workflow definition in a distributed model.
  3. Connectors - Wrapped third-party APIs that allows us to use them.

How to connect EPiServer CMS or Commerce website with Azure Logic Apps. 

Azure logic app designer consists of connectors, triggers, actions and control flows, Its designer looks into open API/swagger of third party APIs and connectors and design cards to use in designing a workflow. Writing a managed connectors can be one way to integrate your EPiServer application, But we can use EPiServer.ServiceApi.Commerce.WebHooks or any webhook to Trigger the workflow and can use EPiServer.ServiceApi.Commerce or any custom API as Action

We presented a working demo at Episerver Close-up 2017 Sweden, Credits: Wessel Terpstra, where on submission of an order was used as a trigger and a custom promotion API was used to prepare a coupon code and post it mail this to the customer.

Image 2017-10-24_1710.png

Prepare your project

Install following packages

  • EPiServer.ServiceApi.Commerce.WebHooks
  • EPiServer.ServiceApi.Commerce
  • EPiServer.ServiceApi(For CMs Projects)
  • Swashbuckle

Create A Trigger

We need to post, purchase order(JSON) to Logic APP 

[ServiceConfiguration(typeof(IWebHookManager), Lifecycle = ServiceInstanceScope.Singleton)]
    public class QuicksilverWebHookManager : IWebHookManager
        public Task VerifyWebHookAsync(WebHook webHook)
            return new Task(() => { });

        public Task<int> NotifyAsync(string user, IEnumerable<NotificationDictionary> notifications, Func<WebHook, string, bool> predicate)
            return Task.FromResult(default(int));

        public async Task<int> NotifyAllAsync(IEnumerable<NotificationDictionary> notifications, Func<WebHook, string, bool> predicate)
            int i = 0;
            var url = "Replace It with your settings"; //Webhook end point retrive from logic app designer when adding a wenhook triger
            foreach (var notification in notifications)
                if (notification.Action != "OrderGroupUpdated" && (Type) notification["OrderGroupType"] != typeof(PurchaseOrder)) continue;
                using (var httpClient = new HttpClient())
                    var json = JsonConvert.SerializeObject(notification);
                    var content = new StringContent(json, Encoding.UTF8, "application/json");
                    var result = await httpClient.PostAsync(url, content);
                    if (result.IsSuccessStatusCode) i++;

            return i;

Create a custom API (to use as Action):

Commerce service API offers a lot but few times those are not just enough and we require some custom API

[AuthorizePermission("EPiServerServiceApi", "WriteAccess"), RequireHttps, RoutePrefix("episerverapi/commerce/promotion")]
    public class PromotionApiController : ApiController
        private static readonly ApiCallLogger Logger = new ApiCallLogger(typeof(PromotionApiController));
        private readonly IContentRepository _contentRepository;
        private readonly IPromotionEngine _promotionEngine;

        public PromotionApiController(IContentRepository contentRepository,  IPromotionEngine promotionEngine)
            _contentRepository = contentRepository;
            _promotionEngine = promotionEngine;

        /// <summary>
        /// Add a new coupon code and return back
        /// </summary>
        /// <param name="username">User name</param>
        /// <returns>returns coupon code</returns>
        [AuthorizePermission("EPiServerServiceApi", "WriteAccess"), HttpGet, Route("{username}")]
        public virtual IHttpActionResult GetCouponCode(string username)
            Logger.LogGet("GetCouponCode", Request, new []{ username});
                var promotionId = ""; // Generate a coupon code
                return ContentReference.IsNullOrEmpty(promotionId) ? Ok("") : Ok(promoCode);
            catch (Exception exception)
                Logger.Error(exception.Message, exception);
                return InternalServerError(exception);

EPiServer integration with azure logic apps(part 2) by Wessel Terpstra

References: What are azure logic apps

  • Workflow - Logic Apps provides a graphical way to model your business processes as a series of steps or a workflow.
  • Managed Connectors - Your logic apps need access to data and services. Managed connectors are created specifically to aid you when you are connecting to and working with your data. See the list of connectors available now in managed connectors.
  • Triggers - Some Managed Connectors can also act as a trigger. A trigger starts a new instance of a workflow based on a specific event, like the arrival of an e-mail or a change in your Azure Storage account.
  • Actions - Each step after the trigger in a workflow is called an action. Each action typically maps to an operation on your managed connector or custom API apps.
  • Enterprise Integration Pack - For more advanced integration scenarios, Logic Apps includes capabilities from BizTalk. BizTalk is Microsoft's industry-leading integration platform. The Enterprise Integration Pack connectors allow you to easily include validation, transformation, and more into your Logic App workflows.
Oct 24, 2017


Please login to comment.
Latest blogs
Plug-in manager is back in CMS 12

Plug-in manager is back in the UI, what is it and how can i use it?

Luc Gosso (MVP) | Oct 6, 2022 | Syndicated blog

Display Child Pages in Content Delivery API Response

The below example will implement an instance of IContentConverterProvider to customise the serialisation of PageData and output child pages in the...

Minesh Shah (Netcel) | Oct 4, 2022

Bring the Report Center back in Optimizely CMS 12

The Report Center has been a part of Optimizely CMS since its first debut in version 5R2 in 2008, but in CMS 12, it's removed! Don't despair! Make...

Tomas Hensrud Gulla | Oct 4, 2022 | Syndicated blog

Customizing Property Lists in Optimizely CMS

Generic property lists is a cool editorial feature that has gained a lot of popularity - in spite of still being unsupported (officially). But if y...

Allan Thraen | Oct 2, 2022 | Syndicated blog

Optimizely names Luminary Senior Developer, Ynze Nunnink, OMVP

Luminary Senior Developer and Optimizely Lead, Ynze Nunnink has secured the coveted position of Optimizely MVP. Earning a Platinum badge for his...

Ynze | Oct 2, 2022 | Syndicated blog

Content Delivery API – The Case of the Duplicate API Refresh Token

Creating a custom refresh provider to resolve the issues with duplicate tokens in the DXC The post Content Delivery API – The Case of the Duplicate...

David Lewis | Sep 29, 2022 | Syndicated blog