web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :

Extending Flow with Functions - Part 2

pwapp_explorer Profile Picture pwapp_explorer 28

Very often there are packages out there, that we could use to extend our flow with more functionality.

 

In this article I will show you how to extend flow, using Azure Functions. The technique I'm going to use is:

 

  1. Create an Azure Function that take some input, does some processing, and returns a result;
  2. Test the function to show how it works as an API;
  3. Write a custom connector, so we can integrate with Flow (and PowerApps);
  4. Use it in Flow

In the first Part of this series, we created the Azure Function, and now in the second part, we will write the custom connector and use it in Flow.

 

Custom Connector- here we go

 

A Custom Connector is way for us to define an interface for Power Platform to communicate with our API - which in this case is the Function App we just created. We define this using OpenAPI 2.0 (formally swagger). There are a lot of tools out there to help you create your OpenApi(such as OpenApiGen), but for this we just going to create it using the swagger editor to create it.

 

Change the following parts of the OpenApi:

  • host - set the host to the url of your azure function app
    host: "liquid-flow.azurewebsites.net"
  • basepath - set this to the base of the function app, by default will be /
    basePath: "/"
  • schemes - function apps only use https
    schemes:
    - "https"
  • Add the function, so path is /api/Liquid
    /api/Liquid:
  • Parameters have a body
     parameters:
     - in: "body"
     name: "liquidbody"
     description: "Liquid Transformation"
     schema:
     $ref: "#/definitions/LiquidBodySchema"
  • Response will have return an object
    responses:
     200:
     description: "OK"
     schema:
     $ref: "#/definitions/LiquidResponseSchema"
  • Add the request schema
    definitions:
     LiquidBodySchema:
     type: "object"
     properties:
     liquidtemplate:
     type: "string"
     description: "The Liquid Template to transform"
     x-ms-summary: "Liquid Template"
     data:
     type: "object"
     description: "Data to transform"
     x-ms-summary: "Data"
  • Add the response schema
     LiquidResponseSchema:
     type: "object"
    By returning just an object, anything can be returned in the response

Get the JSON version, by choosing "Convert and save as JSON" from the File menu

json.png


Here are the completed files:

Add the custom connector

 

Lets upload our OpenApi file into PowerApps, so in PowerApps, select Data - Custom connectors
custommenu.PNG

Click on the right hand side "Create custom connector"

createc.PNG

Connector name is Liquid Templates, and add the OpenApi file
connectcreaet.PNG

 Click Create Connector and it will create the custom connector.

done.png

Test the connector

To test the connector, click on the Test tab
test.PNG

Create a New connection, and then put some test data into the two field:

testpnael.PNG

 

Click the Test operation button, and you should get the result back.

 

200.PNG

 

NOTE: If have just created the connection, and you get a Operation failed (404), see response below error, it doesn't mean you have an error - it's PowerApps way of telling you its still setting everything up - go get a coffee and come back in 10 or 15 minutes time. Hopefully by then PowerApps has setup all the bits to get the custom connection done, and you'll get your 200 response with the output.

 

So we now have:

  1. Created our function app, and tested it;
  2. Created our custom connector, and tested it.

So lets use it in our flow.

 

Add it into our flow

 

Create a new flow, using a button
 flowbutton.PNG

 

Add the new action, so under Custom in the choose action box, the Liquid Templates will appear
liquidtemplates.PNG

Choose the new Transform JSON using Liquid Templating engine
action.PNG

Insert the liquid template, and test data

extemplate.PNG

Save the template, and then run it from the Flow mobile app, by pressing the button

file.jpeg

Now you see the result

result.PNG

We have extended flow - by creating a new action in Flow - this case to transform Liquid Templates.

 

We did this by using an Azure Function, which used an already developed package to offer functionality in Flow.

 

I hope this shows you the possibilities that you can achieve by extending flow, and how to go about it.

Comments

*This post is locked for comments