Invoke an Azure Function Using Power Automate (Flow)

In our previous post, we created a PowerShell Azure function which could Convert a document to PDF.

In this article we will invoke that Azure Function using Power Automate and create a Flow that automates conversions using The Muhimbi PDF Converter Services Azure Function.


Prerequisites / Before we begin:

  1. Please make sure you have configured your Azure Function with reference to this article.
  2. An Office 365 subscription with SharePoint Online license.
  3. Appropriate privileges to create Flows.


Now that we have all the prerequisites in place, lets get started:

From a high level our Flow looks as follows:

When a file is created or modified (properties only) 
Get file content 
Create file


Step 1: Open the Power Automate designer, create a Flow and find the “When a file is created or modified (properties only)” trigger.  This trigger will start the Flow when a file is added to a document library, or when an existing file is updated.

In the action, point the Site Address to the SharePoint Online site-collection you want to monitor for new items.  Then, specify the Library Name within the site to monitor. The Folder within the library can optionally be specified as well.

This image has an empty alt attribute; its file name is trigger.png

Step 2:  Add the SharePoint “Get file content” action to the Flow Canvas and configure it with reference to the details below:

  • Site Address: Specify the path to the SharePoint Online site-collection which holds the file to be converted.
  • File Identifier: “Identifier” the output from the “When a file is created or modified (properties only)” action.
' 「 Identifier 
' Add 
Get file 《 on 彐 
Identifier

Step 3: This is were the real magic happens. Add the “HTTP” action to the Flow Canvas and configure it with reference to details below.

{
  "SourceFileContent": "@{base64(body('Get_file_content'))}",
  "Filename": "@{triggerBody()?['{FilenameWithExtension}']}"
}

Note: For the SourceFileContent in the request “Body”  I am using the “Expression” “base64(body(‘Get_file_content’))“

For more details please refer to the screenshot below:


Step 4:   Use the “Create file” SharePoint action to create the PDF document in the SharePoint document library.

  • Folder Path: Specify the output path to write the PDF file to.  Make sure this is different from the folder of the input file to prevent ‘recursive’ flows.
  • File Name: “Name” the output from the “When a file is created or modified (properties only)” action.
  • File Content: Set it to “Expression”  “base64ToBinary(body(‘HTTP’))”.

Note: The SharePoint “File Content” expects a Binary String, in the above step we converted the Base64 string to Binary using the expression we added to the “File Content” line, as shown in the image below.

That’s it- you’re done!  Publish your Flow and upload a supported file type to the folder that is monitored by the specified SharePoint trigger. After a short wait, you can find the PDF in the output folder.


Subscribe to this blog for the latest updates about SharePoint Online, Microsoft Flow, Power Apps and document conversion and manipulation using The PDF Converter.

2 thoughts on “Invoke an Azure Function Using Power Automate (Flow)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s