Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
39957 มุมมอง

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
14558
1
มี.ค. 15
13940
2
ส.ค. 25
2400
Controller not working แก้ไขแล้ว
2
มิ.ย. 25
719
1
พ.ค. 25
982