Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
39950 Tampilan

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?  

Avatar
Buang
Penulis Jawaban Terbai

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

Avatar
Buang
Jawaban Terbai

You can get the request body by using this

request.jsonrequest


Avatar
Buang
Jawaban Terbai

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?

Avatar
Buang

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

Post Terkait Replies Tampilan Aktivitas
0
Feb 17
14556
1
Mar 15
13936
2
Agu 25
2399
2
Jun 25
710
1
Mei 25
977