Publishing REST service to accept x-www-form-urlencoded

0
Hi, I am working on integrating Slack into an app and the Slash Command feature in Slack makes a post to my app with parameters in the body that are x-www-form-urlencoded.  I cannot seem to get these parameters cleanly parsed into my app.  Has anyone else had success with this?  I can see the entire body with all of the parameters but it would be tedious to parse through that string to look for the = and the & etc.  Is there a native way to extract these parameters from the content body? 
asked
4 answers
0

Not to my knowledge.

Since 7.12 https://docs.mendix.com/releasenotes/studio-pro/7.12#fixes it says “Custom handlers can now access the body of application/x-www-form-urlencoded requests. (Ticket 61729)”. Nothing more than that and no help to you since you can see the entire body already. So likely your stuck with building the parsing yourself.

Maybe this also helps: https://www.urldecoder.org/

 

answered
0

You have access to the body when your microflow takes a System.HttpRequest parameter. The microflow would need to parse the body.

answered
0

Hi Johnathan,

Is this the api that you are using? 

https://api.slack.com/slash-commands

 

if so, it looks like you will get a response that looks similar to this 

token=gIkuvaNzQIHg97ATvDxqgjtO
&team_id=T0001
&team_domain=example
&enterprise_id=E0001
&enterprise_name=Globular%20Construct%20Inc
&channel_id=C2147483705
&channel_name=test
&user_id=U2147483697
&user_name=Steve
&command=/weather
&text=94070
&response_url=https://hooks.slack.com/commands/1234/5678
&trigger_id=13345224609.738474920.8088930838d88f008e0

 

and you are looking for an easy way to parse this. 

 

I dont think there is a native way to do this but the community commons module has a string split java action. You can use that to split on the ‘&’ and the ‘=’ (like you mentioned above).

The microflow would look similar to this

https://modelshare.mendix.com/models/ffa6e112-0033-4adf-bd35-99627d7053b7/parse-url-encode

Once you get the parameter values, you can use the urlDecode string function.

https://docs.mendix.com/refguide/string-function-calls

 

Hope this helps!

answered
0

image.png

you should do this

answered