This question has been flagged
2 Replies
17482 Views

Currently Trying to call a odoo controller which return json data as per my exception .

@http.route('/web/update_order_webhook', type='http', csrf=False, auth="public")
def update_order_webhook(self, **kwargs):
    return Response(json.dumps({"yes":"i am json"}),content_type='application/json;charset=utf-8',status=200)

when i tried to call this end point

import requests

url = "http://159.89.197.219:8069/web/update_order_webhook"

headers = {
    'content-type': "application/json"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)

I get Request Body

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Invalid JSON data: ''</p>

And Request Header at my calling end point

content-length →137
content-type →text/html
date →Thu, 11 Jan 2018 20:32:53 GMT
server →Werkzeug/0.13 Python/3.5.2

that clearly mean that i am not getting json response data from my odoo endpoint . Please correct me if i am wrong at any point. Thanks for your time

Avatar
Discard
Best Answer

Use type='json' instead of type='http' in decorator parameters


To get JSON data I use:
curl -i -X POST -H "Content-Type: application/json" -d "{}" localhost:8069/edi/get_json_orders

or python
url = "http://localhost:8069/edi/get_json_orders"
headers = {'content-type': 'application/json' }
payload = {}
response = requests.post(url, headers=headers, data=json.dumps(payload))


Avatar
Discard
Best Answer

n the controllers decorator `@route` you define a type='http' and request with header "application/json".

Odoo dispatcher will create a JsonRequest Object and expect to receive a json object along with the request.

Change header's 'content-type' to 'message/http' and it should be fine.

Avatar
Discard