Consuming REST API using HTTP connector of Power Automate Flow from Power Virtual Agents

By | September 27, 2021

Power Virtual Agents are the no-code/low-code Chatbot offering within its Power Platform offering. An intuitive drag and drop interface helps to get started quickly with building your first interactive bot that can assist your users with common queries with the ability to handover to human agent when it is beyond the bot to respond to the questions asked.

The good thing about Power Virtual Agent is the ability to call Power Automate flows to execute any action that requires integration with Dataverse or Dynamics 365 CRM or any 3rd party system for that matter empowering the citizen dev to create a powerful bot to assist their customers.

In this blog we will have a look at integrating Power Virtual Agents with an external api and displaying the responses returned to the user.

You can now go ahead and create chatbots from the maker portal at https://make.powerapps.com. You can take help of Microsoft document to create your bots.
I picked up an existing topic and using the canvas designer modified the flow per my requirements.

The conversation flow would be triggered if the user asks about store location
Next ask the user to enter location
Send the location to Azure Maps location service to determine the city and state
If an invalid zipcode was entered, we respond with “Currently not servicing this location” else “We deliver at this location”

Here is the what the Power Virtual agent flow looks like

Consuming REST API using HTTP connector of Power Automate Flow

Once the user provides the address location, we use Power Automate Flow for further processing.
You can use the Call and action option and Create a flow to perform your operations

Consuming REST API using HTTP connector of Power Automate Flow

When a flow is created from the context of Power Virtual Agent it automatically brings up a flow with the “When Power Virtual Agents calls a flow”

Consuming REST API using HTTP connector of Power Automate Flow

This trigger lets you define input parameters that you will pass from the chatbot to the flow. In this case I have defined postalcode parameter.

Next, we will use the http connector to send the request to Azure Maps to get the location details

Consuming REST API using HTTP connector of Power Automate Flow

Use the Parse JSON action to easily extract the required information from the response returned by the http request. Parse JSON requires you to provide a sample response template that it can use to generate dynamic properties that you can directly refer further down in your flow steps without the need for using expressions. To generate a sample response, you can execute the request through API tester like Postman

Consuming REST API using HTTP connector of Power Automate Flow

Copy the result and paste it in the window that comes up on clicking Generate from sample

Consuming REST API using HTTP connector of Power Automate Flow

With this done now you can use the Return values to Power Virtual Agents action to return the results back to PVA.

Consuming REST API using HTTP connector of Power Automate Flow

The complete flow looks as follows

Consuming REST API using HTTP connector of Power Automate Flow

Now that the flow is ready, we get back to our PVA canvas designer and go ahead and select this flow as a step in the PVA.

The flow was designed to accept a user input Postal Code and return City, Country and Result as output results. The same can be seen below.

Choose the value from the Chat bot that you would like to pass as the value for the Postal Code input.

Consuming REST API using HTTP connector of Power Automate Flow

We had accepted the user input of location in a variable and we pass the same as a parameter here

Consuming REST API using HTTP connector of Power Automate Flow

The output results of City and Country can be used in the Show Message action of the PVA

Consuming REST API using HTTP connector of Power Automate Flow

Lets go ahead and test our PVA

Consuming REST API using HTTP connector of Power Automate Flow

And if you enter an invalid post code

Consuming REST API using HTTP connector of Power Automate Flow

Integrating Power Automate Flows with Power Virtual Agents provides you with limitless opportunities to integrate with various 3rd party systems those that have their own connectors for Power Automate or use the http connector and connect with any API directly.

Marketing4Dynamics

2 thoughts on “Consuming REST API using HTTP connector of Power Automate Flow from Power Virtual Agents

  1. Mihai

    Hello,

    Thank you for this tutorial it’s very usefull, but can i have all the steps of this flow? i need please..

    Regards,

    Mihai

    Reply
    1. Inogic

      Thanks for your comments. Please let me know for which steps you want additional detailed steps. I will provide you the steps accordingly.

      Thanks!

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *