<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Derek’s Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/derekli/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/derekli/feed.xml</link>
    <description>Just another Developer Network site</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:41:29 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Customize Approval Workflow in Logic Apps</title>
      <link>https://docs.microsoft.com/archive/blogs/derekli/customize-approval-workflow-in-logic-apps</link>
      <pubDate>Fri, 09 Feb 2018 15:18:04 GMT</pubDate>
      <dc:creator><![CDATA[Derek Li (AZURE)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/derekli/?p=206</guid>
      <description><![CDATA[Recently I had a Logic Apps customer asking me how to customize "Send Approval Email". For those who...]]></description>
      <content:encoded><![CDATA[Recently I had a Logic Apps customer asking me how to customize "Send Approval Email". For those who are not familiar with the action, it sends out an e-mail with options that recipient can choose, and the selection will be passed back into Logic Apps, and you can use "Conditions" or "Switch case" to execute different logic.

However, this customer want to allow the recipient to add a comment, or upload a file when making the selection. This is not something Logic Apps support out-of-box. But because of the modality of Logic Apps, it is possible to implement this yourself, and I thought I'd share it with you.

Our implementation requires three Logic Apps:
<ul>
 	<li>The first Logic App will be triggered by the event you specified -I just used a "Request" trigger for demo purpose- and process any business logic after user made a selection.</li>
 	<li>The second Logic App will start with a request trigger, to be called by the first Logic App, and sends out the e-mail.</li>
 	<li>The third Logic App will serve a single-page web application for user to make selection, and supply supplemental data.</li>
</ul>
Let's get started.

The first Logic App is very simple:

<img src="https://msdnshared.blob.core.windows.net/media/2018/02/15.jpg" alt="" width="609" height="461" class="alignnone size-full wp-image-215" />

Second Logic App is as follows. I used Campaign Monitor's <a href="https://buttons.cm/">Bulletproof email buttons</a> to generate the button with some nice visual. But the key part is to stitch the 3rd Logic App's request url, with 1st Logic Aapp's callback Url.

<img src="https://msdnshared.blob.core.windows.net/media/2018/02/22.jpg" alt="" width="1021" height="765" class="alignnone size-full wp-image-265" />

The 3rd Logic App will serve as the single-page web app, here I used form to allow user to specify a comment, and the action will make a POST call to 1st Logic App's callback url. I'm sure any web developer can make a better looking UI than what I have here.

<img src="https://msdnshared.blob.core.windows.net/media/2018/02/31.jpg" alt="" width="1023" height="396" class="alignnone size-full wp-image-235" />

Now all three Logic Apps are built, we can trigger a manual run on the 1st Logic App, and the email address you specified in the 2nd Logic App should receive an e-mail that looks something like below.

<img src="https://msdnshared.blob.core.windows.net/media/2018/02/61.jpg" alt="" width="349" height="329" class="alignnone size-full wp-image-275" />

Clicking the button should take you to a web page:

<img src="https://msdnshared.blob.core.windows.net/media/2018/02/41.jpg" alt="" width="431" height="101" class="alignnone size-full wp-image-245" />

Type in some comment, and click "Reject". Now navigate back to the 1st Logic App, you should see the webhook action completed with the data we just entered.

<img src="https://msdnshared.blob.core.windows.net/media/2018/02/51.jpg" alt="" width="621" height="584" class="alignnone size-full wp-image-255" />

What's next?
<ul>
 	<li>Add more actions to the first Logic App, you will want to check the body of the request in webhook with a "Condition" or "Switch case" and execute different business logics.</li>
 	<li>The email approval request is sent to can come from the first Logic App and passed into the second. Similarly, approval options from the 3rd Logic Apps can also be passed in from upstream.</li>
 	<li>Make the single-page web app looks prettier. The response to the callback url request is always a 200 with no data, but you may be able to add a 4th Logic App to serve better content upon receiving the response. (The form would submit payload to the 4th Logic App, which will response a prettier message, and then pass the data to Logic App #1)</li>
</ul>
&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Use API-M To Mask Async APIs When Moving Implementation to Logic Apps/Functions</title>
      <link>https://docs.microsoft.com/archive/blogs/derekli/use-api-m-to-mask-async-apis-when-moving-implementation-to-logic-appsfunctions</link>
      <pubDate>Mon, 04 Dec 2017 02:51:49 GMT</pubDate>
      <dc:creator><![CDATA[Derek Li (AZURE)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/derekli/?p=105</guid>
      <description><![CDATA[I recently talked to a customer who is in the process of moving API implementation to Logic Apps...]]></description>
      <content:encoded><![CDATA[I recently talked to a customer who is in the process of moving API implementation to Logic Apps (with request trigger and response action).

The Logic App act as an Azure Function orchestrator, connecting them together and pass data along from one to the other. A single run usually complete within 2 minutes, however, if the Function App went cold it may take more than 2 minutes.

Here's a mock Logic App to simulate this scenario, notice the 150 seconds delay.

<img src="https://msdnshared.blob.core.windows.net/media/2017/11/52.jpg" alt="" width="612" height="733" class="alignnone size-full wp-image-125" />

&nbsp;

Logic Apps has a 120-second request timeout, as documented <a href="https://docs.microsoft.com/azure/logic-apps/logic-apps-limits-and-config">here</a>, so if the run last more than 2 minutes, the connection will be closed and respond will not be available to the caller.

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/Screen-Shot-2017-12-04-at-1.55.42-AM-1024x275.png" alt="" width="1024" height="275" class="alignnone size-large wp-image-205" />

The recommended approach is to enable "Async response" on the settings page of the response action, in which the Logic App will return 202 with a location header immediately, and the caller can check the location url until the run reaches its terminal state.

<img src="https://msdnshared.blob.core.windows.net/media/2017/12/Screen-Shot-2017-12-04-at-1.53.03-AM-1024x358.png" alt="" width="567" height="235" class="alignnone  wp-image-195" />

<img src="https://msdnshared.blob.core.windows.net/media/2017/11/81-1024x311.jpg" alt="" width="1024" height="311" class="alignnone size-large wp-image-145" />

However, this would require updating the client (caller) to follow location header on 202, which is not possible in this case.

API Management came to the rescue.

With API Management policy, it could allow us to enable "Async response" in Logic Apps, yet expose (or in other word, mask) the request trigger as if it's a synchronous call.

&lt;outbound&gt;
&lt;base /&gt;
&lt;retry condition="@(((IResponse)context.Variables["var"]).StatusCode == 202)" count="10" interval="30"&gt;
&lt;send-request mode="new" response-variable-name="var" ignore-error="false"&gt;
&lt;set-url&gt;@(context.Response.Headers["location"][0])&lt;/set-url&gt;
&lt;set-method&gt;GET&lt;/set-method&gt;
&lt;/send-request&gt;
&lt;/retry&gt;
&lt;return-response response-variable-name="var" /&gt;
&lt;/outbound&gt;

&nbsp;

Above outbound policy will keep retry the url specified in header "location" at a pre-defined interval (30 seconds in my case), and only return the terminal payload to the caller. And calling the API-M endpoint appears as a synchronous call.

&nbsp;

<img src="https://msdnshared.blob.core.windows.net/media/2017/11/Screen-Shot-2017-12-04-at-1.50.26-AM-1024x241.png" alt="" width="1024" height="241" class="alignnone size-large wp-image-185" />]]></content:encoded>
    </item>
    <item>
      <title>Use Azure Scheduler to Enable/Disable Your Azure Resources On A Set Schedule</title>
      <link>https://docs.microsoft.com/archive/blogs/derekli/use-azure-scheduler-to-enabledisable-your-azure-resources-on-a-set-schedule</link>
      <pubDate>Tue, 13 Sep 2016 17:47:23 GMT</pubDate>
      <dc:creator><![CDATA[Derek Li (AZURE)]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/derekli/?p=35</guid>
      <description><![CDATA[There may comes time when you want to enable/disable your Azure resources on a pre-defined schedule...]]></description>
      <content:encoded><![CDATA[There may comes time when you want to enable/disable your Azure resources on a pre-defined schedule for many reasons, in this post, I want to share one such example using <a href="https://azure.microsoft.com/en-us/services/logic-apps/">Azure Logic Apps</a>.

Many of our Azure Logic Apps customers created workflows with a polling trigger (a type of trigger that performs the check on a set interval). Because Logic Apps charges based on number of executions, depending on the workflow scenario, there may be times when disable such Logic Apps outside of business hours make sense.

While Logic Apps doesn't support this natively yet, it's very easy to do with the help of <a href="https://azure.microsoft.com/en-us/services/scheduler/">Azure Scheduler</a>, let's get started.

First, you need to set up a service principle, this can be done either via the <a href="https://azure.microsoft.com/en-us/documentation/articles/resource-group-create-service-principal-portal/">Portal</a>, <a href="https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/">PowerShell</a>, or <a href="https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal-cli/">CLI</a>. You will need to record <strong>Tenant</strong>, <strong>Client ID</strong>, and generate a <strong>Key</strong>, I called mine "LogicAppsManagement".

Next, find the Logic App that you want to apply the schedule, under "Access control (IAM)", add a new user. Select "Logic App Operator" for role,  and search for the name of the service principle you just created as the user, in my case, it's "LogicAppsManagement".

<img src="https://msdnshared.blob.core.windows.net/media/2016/09/Capture2-1024x188.jpg" alt="Access " width="1024" height="188" class="alignnone size-large wp-image-46" />

Last, create a Scheduler job (and Scheduler job collection if you don't have one already, which is just a container for jobs) with the following action settings:

Action: Https

Method: Post

Url: https://management.azure.com/subscriptions/{subscriptionGuid}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{LogicAppName}/Enable?api-version=2016-06-01 (you can find the documentation for this RESTful API <a href="https://msdn.microsoft.com/en-us/library/azure/mt643788.aspx#Anchor_2">here</a>)

Body: <em>Leave empty</em>

Headers: <em>Leave empty</em>

For Authentication settings:

Authentication type: Active Directory OAuth

Tenant: <em>Tenant value obtained in step 1.</em>

Client id: <em>Client id obtained in step 1.</em>

Secret: <em>Secret obtained in step 1.</em>

Audience: https://management.core.windows.net/

<img src="https://msdnshared.blob.core.windows.net/media/2016/09/Capture21.jpg" alt="Scheduler Job Action" width="628" height="752" class="alignnone size-full wp-image-55" />

Now configure schedule the way you want. For me, I choose to enable my Logic App during workdays at 8am.

<img src="https://msdnshared.blob.core.windows.net/media/2016/09/34.jpg" alt="Scheduler Recurring Settings" width="628" height="490" class="alignnone size-full wp-image-65" />

Now, create another Scheduler job, but change the recurrence to when you want to disable the Logic App, and update the Url accordingly: https://management.azure.com/subscriptions/{subscriptionGuid}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{LogicAppName}/Disable?api-version=2016-06-01]]></content:encoded>
    </item>
  </channel>
</rss>