Export Power Automate to Azure Logic Apps

Jul 22, 2022 7:53 AM

Personal blog
Microsoft
Azure
Power Automate
Azure Logic Apps
CLI

Getting started

With the uprise of Microsofts Power Platform we see more and more Citizen Developers (End user developers) within companies. While it is good to have more tech savvy users, it can also become hard to manage. Especially when a co-worker leaves the company, but had that very important process running in its own Power Platform environment.

While this might be a common scenario, it is also easily fixed with some help from an IT-department and can be transferred to another end user. But it isn't a good idea to make keeping important processes that became critical for day to day operations as well as business continuity depend on users.

Luckily, when it comes to Power Automate, it uses the same engine as Azure Logic Apps when it comes to Cloud workflows. This will allow the IT-department to main the workflow and guarantee its availability.

NOTE: Not all connectors available in Power Automate will exist in Azure Logic Apps, for this changes might need to occur like using an HTTP request connector to achieve the same result.

Let's check how we can export a Power Automate Cloud workflow to Azure Logic Apps!

Manual export

In Power automate making an export is quite easy. Go to the My flow tab.

Click on the three dots ..., select Export and choose the Logic Apps template (.json) option. A .json version of your Power Automate flow will be exported and downloaded.

NOTE: If Logic Apps template (.json) is not present in your export options, it will mean you have some connectors or steps in your flow that can't be exported directly into Azure Logic Apps. This can also occur for common connectors that are also available in Azure Logic Apps such as the Onedrive for business triggers. If this does happen, it is easier to recreate the flow manually in Logic Apps, until a better solution is presented.

CLI export

From time to time it can happen that a Power Automate flow doesn't want to export in anyway possible. The reasons behind this can vary and are not always clear. Luckily for us we can use the Microsoft 365 CLI to also make an export. Follow the instructions on the Microsoft 365 CLI website to download and install the CLI itself.

With the CLI installed and ready for use we can continue doing so in code. But first we will need to know a two values for the parameters we will need to fill in our code.

Once again go through the Power Automate options to go to Export. Hover your mouse over the Package (.zip) option, Right Click and choose Copy Link Address and paste the URL somewhere.

The URL should look something like https://emea.flow.microsoft.com/manage/environments/Default-31ef9ee9-f712-4369-a573-777d6cd2b362/flows/ed84046e-1129-45de-8968-86b65e024a65/export

As you can see in the URL it contains an ID for the environment, which is Default-31ef9ee9-f712-4369-a573-777d6cd2b362 and an ID for the flow itself ed84046e-1129-45de-8968-86b65e024a65.

With these 2 values available to us, we can add them to our CLI code:

m365 flow export --environment Default-31ef9ee9-f712-4369-a573-777d6cd2b362 --id ed84046e-1129-45de-8968-86b65e024a65 --format json

Change the IDs according to your values and run it. It will produce the same .json file as we saw in the manual export, but now without any hindrance from the Power Automate site if any.

Importing in Azure Logic Apps

The exported Logic App is an ARM template, which means you can use it in the old school way of Infra as Code deployments, but within the .json file you will find the definition property. It might be harder to read since the .json file will be minimised, meaning it isn't formatted in anyway.

Sites likes JsonFormatter can help you make it more readable and easier to spot which part of the code you need to copy. Select everything from definition to the closing bracket behind parameters and copy it.

Assuming you already have created a blank Logic App, you can go to the Code view and select the same properties as before, from start to end and paste your new copied code.

Now you can switch back to the Designer and your Power Automate flow will be imported into your Logic App. Don't forget to hit Save to finalize the process.

What's next?

Recently I entered a discussion about YAML pipelines and external processes. Let's look at how we can embed these in our pipelines. Stay tuned!