Skip to Content
Menu
This question has been flagged

I've defined an @http.route method which receives parameters from a third party. I'm trying to access the body parameters of the request, but I can only access them if they come inside a `params` object. 

For example, I have:

@http.route(['/callback'], type='json', auth="public", csrf=False)
def handler(self, topic=None, **kw ):


and i can only access the `topic` params if in the request it was:

{ "params": {"topic": "foo"} }        


but the third party is doing the request like:

{ "topic": "foo" }        

which I'm unable to fetch. I've tried logging the contents of `**kw` but it logs {}

Thanks

Avatar
Discard
Author

Hey Jack, thanks a lot that was precisely what i needed, sorry I don't have enough karma to comment, upvote or accept the answer :(

Best Answer

Hello Bernado, 

You can use the odoo.http.request lib to grab your post data. 

An example would be:

from odoo import http
from odoo.http import request

class Test(http.Controller):
    @http.route("/test/test/", auth="public", type="json")
    def test_func(self, **kwargs):
        # POST data
        response = request.jsonrequest

Then you can get specific response data using response["topic"]. 

I hope this helps, 

Thanks, 

Avatar
Discard
Related Posts Replies Views Activity
4
Jun 24
663
0
Feb 18
3405
2
Jan 17
17971
1
Nov 22
1714
2
Apr 16
3296