Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing JSON in Azure Logic App

I have a HTTP listener that I am sending a JSON post body with.

{
"recipient":"[email protected]",
"subject":"this is a test subject",
"body":"this is a test body email"
}

I am trying to pull those individual parameters out in the next flow, but it errors instead!

The result I am looking to achieve is "[email protected]" being taken as an input for the next action

I've tried things like

"@{triggers().outputs.body.Content.recipient}"

and various variations of, but I suspect I'm missing something!

edit to add

I am currently sending the post request via Powershell, though it will ultimately be over c#

$a = @"
{"recipient":"[email protected]","subject":"this is a test subject","body":"this is a test body email"}
"@

Invoke-WebRequest -Uri     https://httplistenerc743421edf234899a1315aa38c6398bc.azurewebsites.net/listen -Method POST -Body $a
like image 516
Michael B Avatar asked Sep 03 '15 16:09

Michael B


People also ask

What is HTTP trigger in logic app?

With Azure Logic Apps and the built-in HTTP trigger or action, you can create automated tasks and workflows that can send outbound requests to endpoints on other services and systems over HTTP or HTTPS. To receive and respond to inbound HTTPS calls instead, use the built-in Request trigger and Response action.

How do you foreach in logic app?

The app uses a "Foreach" loop that sends an email for each new item. Create this sample logic app with an Outlook.com account or a work or school account. Between the RSS trigger and send email action, add a "Foreach" loop. To add a loop between steps, move your pointer over the arrow between those steps.

Which liquid template language does Azure logic app use?

Basic knowledge about Liquid template language. Azure Logic Apps uses DotLiquid 2.0.


3 Answers

Ah the trick with this is the output of the HTTP Listener body is a String, so you need to convert it to JSON before you can parse it. There is a @parse() command to do just this.

So if you do this it should work:

@{json(trigger().outputs.body.Content).recipient}

That should give you the recipient. Let me know if that doesn't work.

like image 166
jeffhollan Avatar answered Oct 20 '22 01:10

jeffhollan


You have to define content-type in header of http listener, after which you don't need to parse http listener's response, it will automatically in described format.

like image 27
Vivek Avatar answered Oct 19 '22 23:10

Vivek


as i did with mine where azure function is returning json data as text/string:

@{body('azure_fun_Name').recipient}
@{body('azure_fun_Name').subject}
@{body('azure_fun_Name').body}
like image 29
Ravi Anand Avatar answered Oct 19 '22 23:10

Ravi Anand