Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
15988 Zobrazení

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
Zrušit
Autor

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 :(

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
4
čvn 24
2367
0
úno 18
4433
2
led 17
19322
1
lis 22
2877
2
dub 16
4450