Search code examples
apiexpressodoo

How to get data with rest API and post it in odoo view?


I have created a rest API with ExpressJs to get data from an external database and I want to post it in Odoo view.

I am facing some difficulties while connecting the API with Odoo and posting the data in Odoo view.

I need just a simple basic example.

class Cars(http.Controller):

    @http.route('/CarGClassWaitIn', auth='user')
    def list(self, **kwargs):

        # car = http.request.env['reporting.gclass']
        # cars = car.search([])    
        # return http.request.render('localhost:8000/CarGClassWaitIn')
        response = http.request.render('GET', "localhost:8000/CarGClassWaitIn")

        if response.status_code == 200:
            data = response.json()
            return print("Succesful connection with API.")
        elif response.status_code == 404:
            return print("Unable to reach URL.")
        else:
            return print("Unable to connect API or retrieve data.")

        for record in data:
            return print(record['name'])

Solution

  • You can do with the XML-RPC API, Find more detailed information here Odoo XMl-RPC

    You have to set up the connection and from the RPC-call have a predefined method like create, write, delete, search with use you can perform option in odoo.