cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Receiving an HTTP POST/GET request and responding with XML

Hi all, 

 

I want to receive a POST or a GET from Twilio and respond with XML (TwiML). Here's what my Flow currently looks like: 

EricAlmon_0-1598998731337.png

This is the expression in the body: 

xml(json('{"Response": {"Say": "Hello from Power Automate"}}'))
 
However, it is yielding this:

 

<Response>
<Say>Hello from Power Automate</Say>
div
</Response>

 

Twilio expects something like this: 

<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Say>Hello World</Say>
</Response>

 

It should also be noted that Twilio sends requests with the Content-Type application/x-www-form-urlencoded. I would like to do some logic on the parameters received like this: 

image.png

 

Where "Digits" is one of the parameters in the payload. I am encountering the same problem that @NAR is having in application/x-www-form-urlencoded content type error using when a HTTP request is received  (last post on the thread). 

 

Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @EricAlmon 

 

Thanks for your reply.

 

 

Declare a compose and dynamically map your values like below.

image.png

 

Finally map the compose output to http response.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

View solution in original post

13 REPLIES 13
Highlighted
Super User III
Super User III

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @EricAlmon 

 

Could you post a sample file of the response where it contains Digits?

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Frequent Visitor

Re: Receiving an HTTP POST/GET request and responding with XML

 

{
    "body": {
        "$content-type": "application/x-www-url-formencoded",
        "$content": "AAB1241BACDFA==",
        "$formdata": [
            {
                "key": "msg",
                "value": "Gather End"
            },
            {
                "key": "Called",
                "value": "+1234567891"
            },
            {
                "key": "Digits",
                "value": "1"
            },
            {
                "key": "ToState",
                "value": "STATE"
            },
            {
                "key": "CallerCountry",
                "value": "COUNTRY"
            },
            {
                "key": "Direction",
                "value": "outbound-api"
            },
            {
                "key": "CallerState",
                "value": "AL"
            },
            {
                "key": "ToZip",
                "value": ""
            },
            {
                "key": "CallSid",
                "value": "sid"
            },
            {
                "key": "To",
                "value": "+1234567891"
            },
            {
                "key": "CallerZip",
                "value": ""
            },
            {
                "key": "FinishedOnKey",
                "value": ""
            },
            {
                "key": "ToCountry",
                "value": "CA"
            },
            {
                "key": "ApiVersion",
                "value": "2010-04-01"
            },
            {
                "key": "CalledZip",
                "value": ""
            },
            {
                "key": "MachineDetectionDuration",
                "value": "4213"
            },
            {
                "key": "CallStatus",
                "value": "in-progress"
            },
            {
                "key": "CalledCity",
                "value": "CITY"
            },
            {
                "key": "From",
                "value": "+1234567891"
            },
            {
                "key": "AccountSid",
                "value": "ACCOUNTSID"
            },
            {
                "key": "CalledCountry",
                "value": "CA"
            },
            {
                "key": "CallerCity",
                "value": ""
            },
            {
                "key": "Caller",
                "value": "+1234567891"
            },
            {
                "key": "FromCountry",
                "value": "US"
            },
            {
                "key": "ToCity",
                "value": "CITY"
            },
            {
                "key": "FromCity",
                "value": ""
            },
            {
                "key": "CalledState",
                "value": "ON"
            },
            {
                "key": "FromZip",
                "value": ""
            },
            {
                "key": "AnsweredBy",
                "value": "human"
            },
            {
                "key": "FromState",
                "value": "AL"
            }
        ]
    }
}

 

Highlighted
Super User III
Super User III

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @EricAlmon 

 

Thanks for your reply. So what you are looking is if the file contains "Digits" as key you want to execute the No condition? Is that correct?



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Frequent Visitor

Re: Receiving an HTTP POST/GET request and responding with XML

I would like 2 events: 

1) If the "Digits" key = 1

2) If there is no "Digits" key

 

 

Highlighted
Super User III
Super User III

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @EricAlmon 

 

Please see below. Here under Parse JSON pass your JSON data under the content.

 

Copy the below content under Schema.

 

{
    "type""object",
    "properties": {
        "body": {
            "type""object",
            "properties": {
                "$content-type": {
                    "type""string"
                },
                "$content": {
                    "type""string"
                },
                "$formdata": {
                    "type""array",
                    "items": {
                        "type""object",
                        "properties": {
                            "key": {
                                "type""string"
                            },
                            "value": {
                                "type""string"
                            }
                        },
                        "required": [
                            "key",
                            "value"
                        ]
                    }
                }
            }
        }
    }
}

 

image.png

 

 

Expression I used is as follows:

int(items('Apply_to_each')?['value'])


Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Frequent Visitor

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @abm ,

 

Thank you for this reply. I also need to respond with XML in the Response action in the format outlined in the original post. Could you post a solution to this too?

Highlighted
Super User III
Super User III

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @EricAlmon 

 

You could create a compose action and add the xml

 

<?xml version="1.0" encoding="UTF-8"?>
<Response>
     <Say>Hello World</Say>
</Response>

 

Map the values if required inside your XML. Finally under the response map the compose.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Frequent Visitor

Re: Receiving an HTTP POST/GET request and responding with XML

@abm , how do I do this? 

 


Map the values if required inside your XML. Finally under the response map the compose.


I am still new to the xml() function. Is this what should be used? Could you provide an example on this?

 

Thank you!

Highlighted
Super User III
Super User III

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @EricAlmon 

 

Thanks for your reply.

 

 

Declare a compose and dynamically map your values like below.

image.png

 

Finally map the compose output to http response.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

View solution in original post

Highlighted
Frequent Visitor

Re: Receiving an HTTP POST/GET request and responding with XML

@abm , 

 

When I try to run the flow, there is the following error with Parse JSON: 

 

Unable to process template language expressions in action 'Parse_JSON' inputs at line '1' and column '5386': 'Required property 'content' expects a value but got null. Path ''.'.

 

What do you think is going wrong here? 

 

I used your Schema: 

 

{
    "type": "array",
    "properties": {
        "body": {
            "type": "object",
            "properties": {
                "$content-type": {
                    "type": "string"
                },
                "$content": {
                    "type": "string"
                },
                "$formdata": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "key": {
                                "type": "string"
                            },
                            "value": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "key",
                            "value"
                        ]
                    }
                }
            }
        }
    }
}

 

 

Highlighted
Super User III
Super User III

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @EricAlmon 

 

Looks like you have null values. See the runtime history and check the values.



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials
Highlighted
Frequent Visitor

Re: Receiving an HTTP POST/GET request and responding with XML

@abm , thank you for the quick reply. Yes, my payload does have empty values by default.

Is there any work around on the PA side? 

Highlighted
Super User III
Super User III

Re: Receiving an HTTP POST/GET request and responding with XML

Hi @EricAlmon 

 

Try removing the below from your schema.

 

"required": [
                            "key",
                            "value"
                        ]

 

Also in Power Automate check in relevant action steps check whether its null or not otherwise it will fail again in other steps.

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog

Power Automate Video Tutorials

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Users online (5,902)