How to configure Logic App Standard workflow behind Azure APIM

{tocify} $title={Table of Contents}

Introduction

The feature to directly import from “Create from Azure Resource(Logic App)” is not available for workflows in Logic App (Standard) yet. 

However, the workflows can be put behind in APIM manually, just need to understand bit of it's semantics.

Below we will see how to do it with an example.

But before that why should we add Logic app in APIM?

There are many benefits to using APIM in front of Logic Apps. Here are some of the key benefits:

Security: APIM provides a number of features to help protect and secure APIs, including API key management, OAuth 2.0 authentication, and rate limiting. This can help to protect your Logic Apps from unauthorized access and misuse.

Scalability: APIM can help to scale your Logic Apps by providing a single point of entry for all requests. This can help to improve performance and reliability.

Manageability: APIM provides a number of features to help you manage your Logic Apps, including API documentation, analytics, and alerts. This can help you to track usage, identify problems, and make informed decisions about your Logic Apps.

Abstraction: APIM can help to abstract the implementation details of your Logic Apps from your consumers. This can make it easier to consume your Logic Apps and can also help to protect your intellectual property.

Transformation: APIM can be used to transform the data that is passed between your Logic Apps and your consumers. This can be useful for a variety of purposes, such as converting data formats or adding security headers.

Here are some additional benefits of using APIM in front of Logic Apps:

Caching: APIM can be used to cache API responses, which can improve performance.

Monitoring: APIM provides analytics and monitoring features that can help you track the usage and performance of your Logic Apps.

Logging: APIM can be used to log API requests and responses, which can help you troubleshoot problems.

Versioning: APIM can be used to version your APIs, which can help you to manage changes to your Logic Apps.


Creating a solution

For the sake of walkthrough,

i. Create a Logic app standard with two workflows in it 

ii. Create API in APIM - which represent Logic APP and configure the workflows as operations in the API

1. Create Logic app standard and add multiple workflows in it

Create a logic app (Standard) and add two workflow

Workflow to insert entity in Azure Table
Workflow 1- Http trigger based Workflow to insert entity in Azure Table. Save it and capture the url.

Http trigger based Workflow to update entity in Azure Table

Workflow 2- Http trigger based Workflow to update entity in Azure Table

Save it and capture the url.

Following are the url's which we will use in next step

wf1 url - https://tf-poc-la.azurewebsites.net:443/api/lawf-sample1/triggers/When_a_HTTP_request_is_received/invoke?api-version=2022-05-01&sp=%2Ftriggers%2FWhen_a_HTTP_request_is_received%2Frun&sv=1.0&sig=gr-bCDsemB9Rrup1IHlaOq4Ye7ca8QnOVZHVgzcPCGo


wf2 url - https://tf-poc-la.azurewebsites.net:443/api/lawf-sample2/triggers/When_a_HTTP_request_is_received/invoke?api-version=2022-05-01&sp=%2Ftriggers%2FWhen_a_HTTP_request_is_received%2Frun&sv=1.0&sig=yVqTI7OjlS-DXea0axI9gXlrCTPKISTJT6YIuuMSkus

Highlighted in yellow is the base url of workflows and rest is the relative url.


Good to know about Base and relative url before we proceed

A base URL is the first part of a URL that identifies the protocol and domain name of a website. It is used as a reference point for all other URLs on the website. 

For example, if the base URL of a website is https://www.example.com/, then all other URLs on that website will begin with https://www.example.com/.

A relative URL is a URL that only contains the path to a resource but not the domain name or protocol. It is used to link to resources within the same website.

For example, if you are on the page https://www.example.com/products/, and you want to link to the page https://www.example.com/products/shoes/, you can use a relative URL like /products/shoes/ instead of an absolute URL like https://www.example.com/products/shoes/.

2. Create API in APIM and add operations in it

First step is to Add an API, select HTTP - which lets us manually define Http api

Add an API in Azure APIM

Provide Name and API URL suffix(optional), this will form the base url of the API

Create a HTTP API in APIM

Next, we add two operations

Add operations in API

First operation - InsertEntity

Add insertentity in operation
Give a Name , select method as Post and against URL give 
name which depicts the purpose, like here /insertentity 

Second operation - UpdateEntity

Add updateentity in operation

Give a Name , select method as Post and against URL give name which depicts the purpose, like here /insertentity 

Now API is created with two operations(Only Frontend configured till now).

LogicAppStandard API with 2 operations

 Next we configure the backend - via policy

I encountered an error while doing so, read about it - https://www.tech-findings.com/2023/09/Error-while-adding-logic-app-standard-workflow-as-operation-in-Azure-APIM.html

We make use of two policy - one to set BaseUrl of Backend and another to set relative url

Add policies in InsertEntity operation

Add policies in InsertEntity operation

<rewrite-uri id="insertentity"
template="/lawf-sample1/triggers/When_a_HTTP_request_is_received/invoke?
api-version=2022-05-01&amp;sp=%2Ftriggers%2FWhen_a_HTTP_request_is_received%2Frun
&amp;sv=1.0&amp;sig=gr-bCDsemB9Rrup1IHlaOq4Ye7ca8QnOVZHVgzcPCGo" />

<set-backend-service base-url="https://tf-poc-la.azurewebsites.net:443/api" />

Add policies in updateEntity operation

Add policies in updateEntity operation

<rewrite-uri id="updateentity"
template="/lawf-sample2/triggers/When_a_HTTP_request_is_received/invoke?
api-version=2022-05-01&amp;sp=%2Ftriggers%2FWhen_a_HTTP_request_is_received%2Frun
&amp;sv=1.0&amp;sig=yVqTI7OjlS-DXea0axI9gXlrCTPKISTJT6YIuuMSkus" />

<set-backend-service base-url="https://tf-poc-la.azurewebsites.net:443/api" />

That's it, save it and test the solution.


Testing

For Testing, you can go to Test tab and grab the request url and use it with any rest api client like postman.

I have used the Test client provided within APIM, provided the body and sent.

Insert entity Testing using APIM
Insert entity Testing using APIM 

Response of InsertEntity Test request

We got the response, that means request reached to the backend (logic app standard workflow) .

How it works

The request url to which request is sent is the URL of Api configured in APIM - https://tfpocapim.azure-api.net/las/insertentity

When request reaches to Inbound section base url of apim api url is set to base url of logic app standard workflow and relative url of apim api url is set to relative url of logic app standard workflow.

https://tfpocapim.azure-api.net/las gets replaced by https://tf-poc-la.azurewebsites.net:443/api/


/insertentity gets replaced by lawf-sample1/triggers/When_a_HTTP_request_is_received/invoke?api-version=2022-05-01&sp=%2Ftriggers%2FWhen_a_HTTP_request_is_received%2Frun&sv=1.0&sig=gr-bCDsemB9Rrup1IHlaOq4Ye7ca8QnOVZHVgzcPCGo

And this is done with the help of the two policies 

            rewrite-uri and set-backend-service




Learn More about Logic App

Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post