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:
What I first do is select the data.json value in the array and parse JSON
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.
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.
Solved! Go to Solution.
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,
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,
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,
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.
@NAR, I'm experiencing the same behavior. Did you ever come up with a way around this limitation?
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:
Here's the schema that worked for me in the above Parse JSON:
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:
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]')
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!
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.