September 2020 ยป Azure Logic App URL Too Long for Webhook ?
Sep 05

Azure Logic App URL Too Long for Webhook ?

Introduction

Microsoft Azure Logic Apps is an Azure cloud service that helps you schedule, automate, and orchestrate tasks, business processes, and workflows when you need to integrate apps, data, systems, and services across enterprises or organizations. Well that is the official definition any way. I like to think of them as a serverless way to bridge the gaps between systems like Slack, CRM, Twitter, Email and other APIs.

What really has always impressed me about Logic Apps is that they are incredibly simple to setup and use, where in years past, you as a developer, would have to write a lot of code to integrate each of the actions that they can take. Instead of having to spend hours per integration point, the work becomes just a few minutes of configuration inside of the Azure Portal and Logic Apps designer.  

That is why I was surprised a few weeks back when I was using an Azure Logic App to integrate with my Kentico Xperience website and internal Slack team. During that work, I received a message from the third-party service that I was using, that my Webhook URL was too long. WTF? “How can a Webhook URL be too long?”, was my first thought when I saw that message. Then when I went to see where I could to configure the URL endpoint in my Logic App, I was again surprised that this didn’t seem possible.

 

The Scenario

First, a little background on the scenario. What I was working on was something a little fun for my team at BizStream. BizStream recently celebrated our 10-year anniversary of being a Kentico Xperience Gold Partner. My marketing team wanted to collect a few short videos of our customers saying congrats to our team. We wanted a simple way to provide a page on our website that customers could record some video. We ended up choosing a service called Pipe.

It was an easy decision to use this service because within about 30 minutes, I was able to add a widget into our Kentico Xperience site. I had a basic landing page with the Pipe video recorder in no time. It allowed our customers to record a video and it uploaded those to a dashboard in Pipe. Our internal marketing team could now watch and download the new assets. We then launched an email marketing campaign to drive our customers to this new landing page. Within a few hours, we were accepting our first few customer recordings. The page with the widget looks like:

 

BizStream Celebrates 10 Years of being Kentico Gold Partners

 

The First Challenge: How to Integrate Pipe with Slack

After refreshing the Pipe dashboard a few times I realized that I didn’t want to manually check for new recordings every 5 minutes. Luckily, there was a tab in the admin tool named Webhooks. I happen to be a big fan of Webhooks and was happy to see this capability. After seeing that I knew that I wanted to get the new video recorded event to show up in our marketing team’s Slack channel.

 

I instantly thought that yes, I can use Azure Logic Apps for this in no time! I fired up the Azure Portal and created a new Logic app. After deciding what is the correct trigger, “When a HTTP request is received”, I quickly had the Logic app configured to create a message in the Slack channel that reported to the marketing team when a new recording was received.

 

Azure Logic App Designer

 

Running it in the Logic app designer worked flawlessly. But when I went to try it for real in the Webhook admin settings in Pipe, the Webhook failed every time and no Slack message showed up in my channel. “What the heck?!” I thought. After some debugging efforts, it turned out the Webhook URL field couldn’t handle the length of the Azure Logic app HTTP Post URL. The Azure Logic app generated URL was too long for Pipe to handle.

The URL that Azure Logic app generated for the When HTTP request is received trigger looks like this:

 

Azure Logic App HTTP Post

 

If you copy out and look at the entire HTTP Post URL field from the screen shot above you see the full URL as:

 

https://prod-31.eastus2.logic.azure.com:443/workflows/a456db78ab075ab020fd10740409173f/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=7VqFXQVJlwcnalgfdOHZliG_xqHzB1nJtJS3dW_wDDE

 

Oh, and don’t worry that’s not my real URL pasted above either. However, if you do a character count on that URL, it is about 223 characters long. The URL actually includes the main workflow path (including region) and some securtiy signature properties in the querystring. That's why its so darn long. Pipe, as well as, other services I have worked with, only allow for 200 characters in the Webhook URL field.

Since the solution was working in the Logic app designer, I knew I had to find a way how to handle the Azure Logic app webhook URL being too long.

 

The Real Challenge: How to Shorten an Azure Logic App Webhook URL

After looking through all the configurations and settings, I settled on the fact that there is nothing inside of Logic apps that allow you to change the URL for an HTTP trigger.  Doing some quick Googling led me to the fact that Azure Logic Apps just do not have this configuration ability, but it also led me to the answer. To shorten or customize your Azure Logic App Webhook URL you need to add a different Azure service into the mix, Azure API Management.

Luckily, I have some experience with Azure API Management. I have used in a few past projects with connecting internal on-premise APIs and Azure App Service APIs to Kentico Xperience projects. I have even spoken about Azure API Management at a few tech conferences.

 

The Solution: Combining Azure Logic Apps and Azure API Management

First, I will be honest, I did not come up with this solution, but I think it’s worth detailing again. I used the excellent Microsoft documentation on how to Import a Logic App as an API in Azure API Management for the majority of the solution. The steps for the whole solution boil down to:

1. Create a new Azure API Management resource.

I used the Consumption based pricing tier for the API Management Service which requires you to use only certain regions in Azure.  I used the “(US) Central US” region. With this configuration we get one million free API calls and a 99.9% SLA for free. If you are going to use this resource for something real you might want to consider a higher pricing tier. I named the resource apim-apppipe to keep the URL short to start with, which ends up as https://apim-apppipe.azure-api.net for the base URL.

 

2. Import the Logic App as an API in APIM

Again, using the documentation this was fairly easy. Your Logic App should show up in the list to import. Give your API a name, I went with logic-addpipe-prod and named the operation recordings. This results in a new API Management URL of:

 

 https://apim-apppipe.azure-api.net/webhooks/v1/recordings (which is a short 57 characters).

 

 

Azure APIM Import Logic App

 

After importing your Logic app, and once you have given the operation it name it looks like this:

 

API in Azure API Management

 

3. Updated the Webhook URL field to the new API in APIM

Since I knew that 57 characters would work (much less than 223), I was confident that the solution would work.

 

AddPipe Webhook APIM

 

Sure enough, after applying the change to call the API from APIM, instead of directly calling the Azure Logic App HTTP endpoint. The solution…. errored out. What? Yes, it errored. It turned out that the post object between Pipe and the real Logic app wasn’t quite pure JSON as I was expecting. It happened to have a wrapping layer of payload={…JSON object within…}.

 

4. [Optional] Use Azure Logic App Expressions to transform HTT Post data

Luckily, I was able to use some expression steps in the Azure Logic app to remove the “payload=” string and convert the string body of the request to a full JSON object because Logic apps have that capability built in (another reason they are awesome). That was done through a combination of initial variable operations that you can massage the data through like this:

 

Azure Logic App Initialize Variable

 

Success: The Message Shows up in Slack

Now that everything works, the final result looks like this from a systems overview perspective:

 

Kentico Azure Logic App Slack

 

 

The final result in the Slack channel looks like this for our marketing team:

 

Azure Logic App Slack Message Result.png

 

You can see that the message contains data from the payload of the webhook post to our Azure Logic app and the marketing team is now clued into the fact that there is a new recording to view all right from within Slack.

 

Conclusion

There is literally a ton more you can do with Azure API Management and Azure Logic Apps and I have only scratched the surface. I hope I have shown that when you need to integrate apps or websites, data, systems, and services across enterprises or organizations Azure Logic Apps is a service that is a good choice. I really like how easy it was to integrate with our Kentico Xperience website at BizStream.com with a third party video recording service that notifies Slack when activity happens. I no longer have to manually refresh any dashboards, and now my marketing team knows when and how much the integration is used.

 

You might also be interested in

[X]

Be the first to know about my latest Kentico Tips & Tricks!

Do not show again