yezyilomo / odoo-rest-api

Module which expose Odoo as a REST API
MIT License
208 stars 167 forks source link

: /api/product.template/: Invalid JSON data: #24

Open NirmalaSudhirr opened 4 years ago

NirmalaSudhirr commented 4 years ago

Hi Yezyilomo, I have been using your repo for last few months. After some code change I was able to login from my flutter app using your odoo-rest-api. I Use postman to play around with the api. I am able to get result for login api with the below code snippet.

      @http.route('/auth/', 
         type='json', auth='public',methods=["POST"], csrf=False, sitemap=False)
        def authenticate(self, *args, **post):
             ........................................

Next I want to get the product list from odoo. I did bit format to your code like this

       @http.route( '/api/product.template/', auth='user', methods=['GET'], csrf=False)
        def get_product_template(self, model, **params):
        records = request.env[model].search([])
        if "query" in params:
          query = params["query"]
        else:
           query = "{*}"
       record = records.browse(rec_id).ensure_one()
       serializer = Serializer(record, query)
       return http.Response(
        json.dumps(serializer.data),
        status=200,
        mimetype='application/json'
    )

When I try to get response from postman (without passing anything in the body). I get the below error

2020-02-20 08:39:07,874 8663 INFO testodoo odoo.http: /api/product.template/: Invalid JSON data: '' 2020-02-20 08:39:07,875 8663 INFO testodoo werkzeug: 127.0.0.1 - - [20/Feb/2020 08:39:07] "GET /api/product.template/ HTTP/1.1" 400 -

Can you please tell me how could I get product list from odoo using your api?

thanks

yezyilomo commented 4 years ago

I think you're missing something in your JSON request, have you checked if you're sending data in the right format?..

altanmur commented 4 years ago

Check this @NirmalaSudhirr

https://github.com/yezyilomo/odoo-rest-api/issues/32#issuecomment-617465669