Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW

Introduction

 
Microsoft has provided tons of connectors in FLOW to interact with hundreds of applications out there. Still, at some point, you might need to build your own connector or build REST APIs which are communicating to your other applications. You call your REST APIs from FLOW easily with HTTP action. This is a powerful action which you can use to pull data, push data, update data. In this article, we are going to look at how we can send JSON data as a body to HTTP action correctly.
 

Problem

 
When it’s  data then, of course, it must be generated dynamically depending upon your source request item. In FLOW you can generate JSON data by contenting the values and storing them in a string variable. But when you pass this string variable to HTTP action it fails. It treats data as a plain text body parameter, not JSON. You will get an UnsupportedMediaType error as shown below.
 
The request entity's media type 'text/plain' is not supported for this resource.
 
Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW
 

Solution

 
Let’s see how to overcome the above error. We need to parse the string into JSON object and then send it to HTTP action.
 
Let’s see how to do it step by step.
 
Login to Microsoft FLOW web service and Edit your FLOW >> Add a variable in which you can store the concatenated string JSON data >> Set the variable with your dynamic content in JSON format.
 
When I say JSON format, I mean a string like {"Parameter1": "Value1", "Parameter2": "Value2"}
 
Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW
 
Add Parse JSON action after it >> Set the Content of this action to your variable, i.e., strJsonData in our case. Now, we need to tell this action how the schema of our JSON data is. So, click on "Use sample payload to generate schema" – this will help to generate the schema automatically instead of typing it manually and making errors.
 
Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW
 
Enter sample JSON data which your REST API function accepts, as shown below >> click on "Done".
  1. {  
  2.    "CaseID""CID-1234",  
  3.    "CaseName""Desk rearrangement"  
  4. }   
Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW
 
That’s how the schema will get generated for your JSON input. Depending on the sample data values, it will see the properties and type. You can change this schema any time if its not supporting to your API. Sometimes, the type might be empty – in that case, you need to explicitly specify it as string.
 
Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW
 
Now, add HTTP action, which we will use to call our REST API and send the above JSON data to it.
Enter your API URL, choose Method POST. 
In the Body section, choose Body from Parse JSON action as shown below.
 
Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW
 
If you want to know how to manage authentication in HTTP action, then, please read this article which explains how to call authenticated APIs from FLOW.
 
We are done here. That’s how all the actions in sequence will look like in the FLOW.
 
Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW
 
It is time to test this FLOW. Click on Test and it should run without any error now. The HTTP action will recognize the JSON data correctly this time.
 
Send JSON Data Using HTTP Action And Parse JSON In Microsoft FLOW
 
To summarize, you need to use the "Parse JSON" action in order to generate the JSON data object from a string and send it to HTTP action.
 
That’s it for this article. Hope this helps. Thanks for reading.


Similar Articles