Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
15992 Ansichten

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

Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
4
Juni 24
2368
0
Feb. 18
4436
2
Jan. 17
19323
1
Nov. 22
2877
2
Apr. 16
4451