Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 6h/Jb6Uk/IOPUWZflExx2I
Power Automate - Building Flows
Answered

How to extract from XML String Output of HTTP Request

Like (0) ShareShare
ReportReport
Posted on 30 Jan 2024 17:30:49 by

Hello everyone,

 

I need to create Change Tasks in ServiceNow via PowerAutomate and am using HTTP Requests to do that. I then need to get the CTASK ID from the Body output of the HTTP Request so that I can update and close the Ctasks in a later step during the release of the software. I have trimmed down the flow to try to just get the id and cannot find a combination to make it work.

 

I can do a compose on the Body of the HTTP Request and get the following: 

<id>CTASK0257585</id><key>GUID_ID_HERE</key>

I then try to do a compose to get just the ID. I have used outputs('compose')?['body']['id'] or body('compose')?['id'] and variations of this with create_ctask and numerous other ideas from the forums and at best I get the click to download which is blank or will get an error saying the id isn't in the body. Any help would be appreciated!

I have also tried parsing a json but the format is xml so won't render into the json to extract the <id>.
 
 Screenshot 2024-01-30 at 10.16.40 AM.png
  • dscull Profile Picture
    on 30 Jan 2024 at 19:30:37
    Re: How to extract from XML String Output of HTTP Request

    @harshdeol If I define the xml in the compose like in your example that works. How do I do that automatically now?

    EDIT: If you do the compose as <root> HTTP BODY </root> it worked.

     

    Screenshot 2024-01-30 at 12.34.56 PM.png

     

    Thank you so much!

  • dscull Profile Picture
    on 30 Jan 2024 at 19:19:09
    Re: How to extract from XML String Output of HTTP Request

    Thanks @wskinnermctc - I tried running 10 more tests using the documents / video for help you provided and just ran into more errors. Can't parse XML file for the XPATH stuff, that wasn't covered in the common questions document. XML file won't port into the JSON to be formatted per the video tutorial. 

    Seems odd I just need to extract the id from the output of the HTTP Response so I can use it in another HTTP Response to update the correct object in ServiceNow, but I can't get that ID to show up. Any other ideas are welcome.

     

    Screenshot 2024-01-30 at 12.18.40 PM.png

  • Verified answer
    harshdeol Profile Picture
    412 Super User 2025 Season 1 on 30 Jan 2024 at 18:57:47
    Re: How to extract from XML String Output of HTTP Request

    Hi @dscull ,

    The goal is to extract the id from XML, Right? Please try below expressions:

    //XML:

    <root>
     <id>CTASK0257585</id>
     <key>GUID_ID_HERE</key>
    </root>

    //Flow Actions and expressions:

    harshdeol_1-1706640988017.png

    //For id:

    join(xpath(xml(outputs('Compose')),'//id/text()'),',')

    //For key:

    join(xpath(xml(outputs('Compose')),'//key/text()'),',')

     

    //Output:

    harshdeol_0-1706640836342.png

     

    -------------------------------------------------------------------------------------------------------------------------
    If your question got an answer, please click "Accept as Solution "✅, If you liked my answer, please hit the "thumbs-up" 👍button.

    Thank you,
    Harsh Deol

  • wskinnermctc Profile Picture
    6,517 Super User 2025 Season 1 on 30 Jan 2024 at 18:17:59
    Re: Get ID from Http Request - Click to Download

    You could try getting the data out of the string using something like xpath(xml(<add string here>),...) that you can read about in Manual T Gomes XPath Function which shows some examples. Just note that his primary example is showing an XML document, where it seems like you are using a string, so you will need to scroll down to the section Common Mistakes and Solutions.

     

    There is also a video about Working with XML in Power Automate by @DeepakS which is also showing XML from file content. But it might help give you an idea.

     

    You could also try changing the topic of your forum post from "Get ID from Http Request - Click to Download" to something like "How to extract from XML String Output of HTTP Request" which might make it easier for people to recognize if they know a solution.

     

    I don't know much about it, but you could look into the functions xml() or xpath() which deal with converting this type of data. I also think there is a way to use json() or parse json action along with xml() and it get things separated.

    Maybe give a direction to search for help.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard
Loading started