Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
39851 Переглядів

Hello, I am trying to create a route allowing "POST" requests on Odoo. The code I have so far is the following:

class SubscriptionRoutes(http.Controller):
@http.route('/subscription/update', type="json", auth='public', methods=['POST'])
def some_html(self, **kw):
return {
'success': True,
'status': 'OK',
'code': 200
}


The request I am sending through Postman has Content-Type = application/json and the following body:

{

"id": "test"

}

How do i access the request's body's data on my controller?  

Аватар
Відмінити
Автор Найкраща відповідь

I solved the problem, by changing the request's body to {"params":{"id":"test"}} and was then able to retrieve the data from http.request.params

Аватар
Відмінити
Найкраща відповідь

You can get the request body by using this

request.jsonrequest


Аватар
Відмінити
Найкраща відповідь

what if i cannot change the request's body to wrap all the params inside 'params' (cause the request is done by a third-party). How would I access plain json body params?

Аватар
Відмінити

@Niyas Raphy If i do `_logger.info(kw)` I get `{}` despite I'm sending some params

Related Posts Відповіді Переглядів Дія
0
лют. 17
14460
1
бер. 15
13853
1
черв. 25
2278
Controller not working Вирішено
2
черв. 25
622
1
трав. 25
926