コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
39897 ビュー

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

関連投稿 返信 ビュー 活動
0
2月 17
14519
1
3月 15
13867
1
6月 25
2310
2
6月 25
663
1
5月 25
955