Skip to Content
Menu
This question has been flagged
4 Replies
39874 Views


In Odoo 11,

I have written a Web Controller to accept JSON data, as follows

class XController(http.Controller):

    @http.route('/test', type='json', auth='public', methods=['POST'], csrf=False)
    def test(self, **post):
        _logger.info('CONNECTION SUCCESSFUL!!')
        _logger.info(post)
        name = post.get('name', False)
        if not name:
            Response.status = '400 Bad Request'
        return '{"response": "OK"}'

Now when I post the data using the following Request, I get JSON Post data correctly without any issues.

headers = {'Content-Type': 'application/json'}
data = {"params" : { 'name': 'Kathy'} }
data_json = json.dumps(data) r = requests.post(url=url, data=data_json, headers=headers)

However since this request is made from an external system, the format of data is sent as follows,

data = {'name': 'Katty'}

ie without params inside data/content, Due to which, my post data is empty, how do I handle this.


Any help appreciated.

Avatar
Discard
Best Answer

you can directly intercept the werkzeug request object and get data from it 
like
        data = json.loads(request.httprequest.data)
you can also get use:  request.httprequest.args


Avatar
Discard
Author

Thank Goodness, you saved me...

Hello Ravi,

Can you provide some resources on how to intercet the werkzeug request in Odoo *before* this line.

https://github.com/odoo/odoo/blob/f1a5ad5f20bf1b885a3c2dc2248b8fb15b2d6565/odoo/http.py#L613

I don't have control over the callback payload, except that it is in JSON

Best Answer

Get it with the jsonrequest attribute

from odoo.http import request

...

data = request.jsonrequest
Avatar
Discard
Best Answer

Odoo mi sembra un sistema abbastanza interessante.

Avatar
Discard

Posso leggere le sue caratteristiche qui https://basketballstarsgame.io

Best Answer

Hello Kathy,

Please refer below link:

https://stackoverflow.com/questions/37111955/how-to-get-json-data-in-an-odoo-controller-using-type-json

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Avatar
Discard
Related Posts Replies Views Activity
0
Mar 17
3883
1
Jun 24
934
0
Jan 21
12352
2
Dec 19
8740
1
Apr 17
11693