cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing HTTP response Body to extract XML parameters

Current HTTP activity in flow is very limited in usability as it doesn't provide means to extract attributes from response body. And passing entire response body to other web request or other activity is so to speak useless. So there should be means provided to extract parameters from three most typical http response types:

1) From XML as Xpath

2) From JSON in simple Javascript expression for navigating body structure

3) From text as simple regex (like in transport rules in Exchange)

 

That would make flow 10x more usable and give it competitive advantage over IFTTT. Most datasources don't support swagger yet, and making swagger proxies requires much effort and infrastructure. Support for above scenarios would allow pass parts of responses from one web requests as parameters to other web requests giving people plenty of new scenarios available on Flow.

 

[Moderator's Note] Clarified this is for XML - JSON is supported today. Regex is suggested here: https://powerusers.microsoft.com/t5/Flow-Ideas/Support-for-regex-either-in-conditions-or-as-an-actio...

Status: Completed

You can now use the xml() expression to parse XML content and the xpath() expression to select a particular XML node. You can read more about using expressions in flow here: https://flow.microsoft.com/blog/use-expressions-in-actions/

Comments
Level: Power Up

Any idea when this ambition may be realized?

Level: Powered On

This is already possible in Flow.

Just create a 'Compose' action and name it. The Compose action is kind of like a variable. In the input for the variable you can use the following conversion functions:

 

"@xpath(xml(outputs('My_HTTP_Request')),'string(/*[name()=\"AuthInfo\"]/*[name()=\"token\"])')"

 

Remember you must place double quotes around this expression in the 'Compose' action input and escape any double quotes you use in your xpath expression.

 

You can see from this example that I am referring to the output of a HTTP request outputs('My_HTTP_Request') that I know is XML.

 

I first cast the output to xml using the 'xml' function and then use the 'xpath' function to extract specific elements from the XML.

 

In this example the XML looks like this:

<AuthInfo>

   <token>ghghgh565656</token>

</AuthInfo>

 

The 'Compose' action above will return 'ghghgh565656'

Power Automate Staff
Status changed to: Completed

You can now use the xml() expression to parse XML content and the xpath() expression to select a particular XML node. You can read more about using expressions in flow here: https://flow.microsoft.com/blog/use-expressions-in-actions/

Level: Power Up

 Hi guys i am stack in how to send request http body to my server using POST method

i all did :

headers: content-type: application/json

body: { "SOS": "help me plz" }

 

but in my server i got empty POST i don't know why ? do i miss something in headers ?? please help

Super User

Hey, thanks very much @TechShed ! Your example should be "Example 1" in the docs! Its at the very bottom. 

Super User

Disregard.