HTTP Requests and Responses in a Flow Demo using Power Automate
Let’s say you want to configure an HTTP service, do some task and then return a response. So how we can build this without any code ? Luckily Power Automate gives a no-code platform to configure this.
An HTTP Request Trigger can be used to receive an HTTP request, process it, and return a response to the target application. First we have to use Request Trigger and add required actions to perform then we can return response.
Let us run through a business scenario.
Business Scenario:
My business scenario is I want to configure a HTTP Request and Response flow which will accept multiple contact records information and use those records to create the contacts in DataVerse then after creation return response with the primary GUID of the created records. Lets us follow the steps below:
Step-1: Create a new Cloud Flow and Choose a Name and Trigger as Request
In Power Automate screen choose create new Cloud flow and give a Name “HTTP Request Response Flow” now after the name search for “Request” trigger then choose the Trigger “When a HTTP Request is Received“. After this step is selected you have to provide the “Request Body JSON Schema“. To generate the schema automatically use the “use sample payload to generate schema“. Then inside the Textbox provide the contact records JSON format as given below. For this example I am using the below sample.
{
"contact":
[
{"firstname":"Robert","lastname":"Keast","email":"robert@gmail.com"},
{"firstname":"Matthew","lastname":"Bedford","email":"matthew@gmail.com"}
]
}
Now click Done to generate the JSON schema. You need not to be worry about schema as it will generate automatically as your sample payload.
Step-2: Add new Step to Create Contact using DataVerse connector
After the HTTP Trigger is created its time to add new step to create row action using DataVerse connector. But as I want to capture all contact records GUID in an array use a initialize variable step of type Array.
After this Click on Add New Step and choose DataVerse then choose an action “Add a new row” by choosing Table name as Contacts.
Now we have to assign the respective fields of the contact create step. Assign First Name, Last name and Email from “When a HTTP Request is Received” step using Dynamic assistance panel. Once you assign you can see a apply for each loop is automatically included for the “Add a new row” step because the request contains multiple contacts records and the create new row will execute in loop.
Now after the records created we have to store the GUIDs of the newly created record in the Result array we have taken before. Now add a new step just after the “Add a new row” step inside the “Apply for each” loop. and use an Append to Array variable. Select the Array and assign the field “Contact” from the dynamics assistance panel which represents as Unique identifier.
Now add a New step outer to For each loop step and choose an action Request then select Response.
In the Body field assign the variable result.
Save the Flow and you will see the Unique HTTP URL will be generated for the flow which will be used whenever we will send a request to this URL.
Now we are ready with the Flow. We can test it.
Step-3: use Postman request to test it
Open Postman and copy paste the URL from Flow in Postman address bar and supply the Raw JSON request as mentioned below.
{
"contact":
[
{"firstname":"Robert","lastname":"Keast","email":"robert@gmail.com"},
{"firstname":"Matthew","lastname":"Bedford","email":"matthew@gmail.com"}
]
}
after providing all these information click on send. The Postman will send a HTTP Request and the flow will trigger which will create the two records we sent, we can check this in response are of Postman.
Now if we check the records in DataVerse then all the records are successfully created.
Now we are DONE.
Thanks for reading this Blog. Hope this helps in your project.