cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mick282
Helper III
Helper III

application/x-www-form-urlencoded content type error using when a HTTP request is received

Hi

 

I'm using a webhook created by Unbounce forms. The problem with the webhook is that it sends the payload with a content type of application/x-www-form-urlencoded. I'm now getting this weird error :

 

 

{
  "error": {
    "code": "InvalidRequestContent",
    "message": "The input body for trigger 'manual' of type 'Request' must be of type JSON, but was of type 'application/x-www-form-urlencoded'."
  }
}

 

 

A sample payload of what is submitted is below:

 

 

{
  "$content-type": "application/x-www-form-urlencoded",
  "$content": "<a base 64 encoded content>",
  "$formdata": [
    {
      "key": "page_url",
      "value": "url of the form"
    },
    {
      "key": "page_name",
      "value": "name of the page"
    },
    {
      "key": "page_id",
      "value": "id of the page"
    },
    {
      "key": "variant",
      "value": "a"
    },
    {
      "key": "data.json",
      "value": "The JSON object containing the field values of the form"
    },
    {
      "key": "data.xml",
      "value": "XML version"
    }
  ]
}

 

 

When I initially setup the HTTP request is received trigger it seems to take the webhook and schema correctly but as I'm adding items to it, it throws the error that it needs fixing. A snippet of the whole flow is below:

 

image.png

 

What I first do is select the data.json value in the array and parse JSON

 

image.png

 

The expression in the Content field is:

 

triggerBody()?['$formdata'][4]

 

Basically I'm selecting the data.json value in the formdata array.

 

I then parse the full JSON value.

image.png

 

The expression in the content is:

 

json(body('Parse_data.json')?['value'])

 

 

It seems to submit and flow correctly during an initial test of the webhook and submission of the unbounce form but any future submissions throws the error:

 

 

{
  "error": {
    "code": "InvalidRequestContent",
    "message": "The input body for trigger 'manual' of type 'Request' must be of type JSON, but was of type 'application/x-www-form-urlencoded'."
  }
}

 

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
v-bacao-msft
Community Support
Community Support

 

Hi @Mick282 ,

 

Do you mean that the body output by the trigger is the sample you provided?

Then this part of the content cannot be used in Parse JSON, because its type is clearly application / x-www-form-urlencoded and not JSON.

You need to extract $ formdata first and then parse it.

Please check the attachment and import it as a new Flow.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
v-bacao-msft
Community Support
Community Support

 

Hi @Mick282 ,

 

Do you mean that the body output by the trigger is the sample you provided?

Then this part of the content cannot be used in Parse JSON, because its type is clearly application / x-www-form-urlencoded and not JSON.

You need to extract $ formdata first and then parse it.

Please check the attachment and import it as a new Flow.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-bacao-msft ,

 

Thanks for sending through the zip file. Quick question. If I use the apply to each, how do I extract the value from key : data.json?

 

Basically that's the only section of the formdata array that I'm interested in.

 

It seems to be caused by an issue with the trigger itself which is the When a HTTP request is received.

 

It won't even register the flow run when I do a test submission

 

Hi @Mick282 ,

 

If you created the Flow using the .zip file I provided, you need to replace the trigger with When a HTTP request is received.

And configure the parameters included in the previous Flow in the trigger.

Then configure the trigger body in Compose. Here I guess that the body output by the trigger is the sample you provided, so a specific method is provided.

 

Regarding extract the value from key: data.json, I'm afraid I don't understand what you mean. Parse JSON has parsed out the data contained in $formdata, you only need to use Dynamic content to get the attribute value directly.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I am having the same issue with this. I have tried your method and it works fine until you add an action that actual does something e.g. CDS List Records. If you don't add an action you can assign a variable and pull the data you require out of the formdata. If you then add an action the flow doesn't even show as running. 

I have sent the data via Postman and without the action it fires fine. With the action it returns the below error message.

 

{
    "error": {
        "code""InvalidRequestContent",
        "message""The input body for trigger 'manual' of type 'Request' must be of type JSON, but was of type 'application/x-www-form-urlencoded'."
    }
}
 
I cannot change the request type as it is coming from an external system, so is there a way to force Automate to accept it.
 
Thanks

Dave
Jronash
Solution Supplier
Solution Supplier

@NAR, I'm experiencing the same behavior.  Did you ever come up with a way around this limitation?

amh15
Frequent Visitor

I'm going to try to post a very quick summary of how I got this to work, with a Mailchimp webhook triggering a flow, wherein I managed to get an object that was addressable using the keys, despite the form being urlencoded.

 

1. Use HTTP Request trigger with the json schema left blank.

2. input that into Parse Json as follows:
 amh15_0-1622990395143.png

 

Here's the schema that worked for me in the above Parse JSON: 

{
    "type""array",
    "items": {
        "type""object",
        "properties": {
            "key": {
                "type""string"
            },
            "value": {
                "type""string"
            }
        },
        "required": [
            "key",
            "value"
        ]
    }
}
 
This produced an array something like this:
[
  {
    "key""type",
    "value""campaign"
  },
  {
    "key""fired_at",
    "value""2021-06-05 00:33:42"
  },
  {
    "key""data[id]",
    "value""20b9073683"
  },
  {
    "key""data[subject]",
    "value""Catching up"
  },
  {
    "key""data[status]",
    "value""sent"
  },
  {
    "key""data[reason]",
    "value"""
  },
  {
    "key""data[list_id]",
    "value""0d8ea2e4ed"
  }
]
 
3. Apply to each on the resulting array to replace open and close square brackets in the key names with _ and with a blank - because we are not going to be allowed associative arrays, nor square brackets in object names:
amh15_1-1622990700403.png

 

Here is the replace I used: replace(replace(items('Apply_to_each_2')?['key'],'[','_'),']','')

And here's the addProperty I used: addProperty(variables('formdata'),variables('cleaned_key_name'),items('Apply_to_each_2')?['value'])

 

You'll notice addProperty adds the cleaned up key name as a new property to the object tempobj. We then assign the value of tempobj into the original property variable formdata that the loop has built up.

 

You end up with an object looking like this:

 

{
  "type""campaign",
  "fired_at""2021-06-05 00:33:42",
  "data_id""20b9073683",
  "data_subject""Catching up",
  "data_status""sent",
  "data_reason""",
  "data_list_id""0d8ea2e4ed"
}
 
If you had nested arrays, they're no longer nicely nested, but you can still directly access the entire nested structure using the names as you can see above.
 
It's not super elegant and if I had been able to get a parse JSON to properly read the nested array as others have suggested elsewhere, I would have preferred that, but it works!

 

Jronash
Solution Supplier
Solution Supplier

Nice solution, @amh15.

 

I'll also mention that the triggerFormDataValue() expression can be very handy in cases like this.  It can grab the value from a specific form field.  For example:

 

triggerFormDataValue('data[id]')

or

triggerFormDataValue('data[subject]')
amh15
Frequent Visitor

For some reason I had rejected that route - perhaps I hadn't figured out how to deal with the square brackets or perhaps I thought the syntax looked awkward -  but you're right, that should work, and in fact I'm not sure there's any real advantage in having it in a single object that way I did, as my dynamically created properties don't pop up in the Dynamic Content UI (Flow has no idea at edit time what they will be), so the syntax of my approach seems no better in the end.

Leaving the schema blank was actually what I needed, thanks!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (3,408)