Forum Discussion
Just to make sure understand this, you do not have control over the client-side logic that is going to be submitting the request to the endpoint you are creating, and whoever controls that code will not be able to modify it to send the JSON as a request parameter instead of in the request body (payload), correct?
Unfortunately we do not currently have a way to parse a request payload from the request via Freemarker. While we do have methods in the http.request object to get request parameters and request headers, we do not currently provide a way to get the entire request body. You could work with our Professional Services group - they are able to add a java-based endpoint that could do this until we have provided a way to do this via Freemarker.
DougS were there any methods added since 2016 that would allow to read a JSON payload in a request body via FreeMarker? Have the same scenario like OP. Sending data that way is quite common for third party API's when sending data via webhook-functionality, e.g. sending back data to some endpoint/webhook after something was done on their platform...
- DougS6 years agoKhoros Oracle
Hi luk ,
Unfortunately we have not added a way to do this yet, but I have taken to heart how long it has been and have added a pull request to add in support for parsing the request body (named http.request.body, in endpoints only) and a utils object for converting to/from a JSON string to a Freemarker hash (utils.json.toJson(hash) and utils.json.fromJson(string)).
I'll update this post once I know what version of the Community product it will go into.
Thanks,
-Doug
- luk6 years agoBoss
DougS that's awesome, thank you very much! Any chance support or professional services could merge that PR into a specific instance? Could you provide the (internal) PR number so I could refer it with support/PS? Currently working on a project where that functionality is needed rather urgently... was planning to create a microservice that would receive the incoming request, extract the request body and forward it to Lithium/FreeMarker in way it can understand.
With that new information this seems kind of unnecessary though, of course that depends on the answer if support/PS can add the new FreeMarker functionality ahead of the official release for a specific client?
Also great to have "official" tools to parse JSON, always had to rely on a custom JSON-parser method in FreeMarker, which was less than ideal, using ?eval and a bunch of ?replace()'s!
Thanks again!
- pp_016 years agoMentor
Hey DougS ,
Is there any update regarding what you have mentioned in your comment because I couldn't find anything related to "get request body in the endpoint" in the current 19.4 and 19.5 release notes. I am also stuck with the same issue mentioned above about how to get payload of a Webhook's POST request in an endpoint. If you can provide any update on this then it will be really helpful.
Thanks in advance.- DougS6 years agoKhoros Oracle
We actually added this back in 19.2, but looks like it didn't make it into any release notes or into our Freemarker documentation -- I will make sure this gets added to our Freemarker documentation. In the meantime, you should be able to do this to parse JSON out of the request body:
<#assign requestBody = http.request.body /> <#assign requestBodyObj = utils.json.fromJson(requestBody) />
(Please note that the http.request.body object will only work when used in Endpoints -- it will throw an exception if used in a component on a community page)
-Doug
Related Content
- 9 years ago
- 12 years ago