Blog_

Create lead in Odoo from web form

Odoo is a great open source software for Customer Relationship Management (CRM) and Enterprise Resource Planning (ERP). It is used by millions of people all over the world.

To improve our sales process, we added a feature on our website to automatically create a lead in Odoo when a visitor fills our contact us form.

To create the new lead, we will use a connector made with NodeJS and odoo-xmlrpc npm package. The connector has an advantage to keep Odoo instantly unmodified by using its core XML-RPC API. An inconvenient point is that you must host this extra third-party Node service somewhere.


Setup NodeJS connector

git clone https://github.com/acte-technology/odoo-lead-connector.git
cd odoo-lead-connector/
npm install
cp .env.example .env

Edit .env file:

PORT=8081

#Odoo
ODOO_HOST="https://odoo.com"
ODOO_USER=""
ODOO_PASS=""
ODOO_DB=""

To increase security, you should set up a new Odoo user with very limited access.

Then start server:

node server.js

Test it with Postman

Screenshot 2020-10-17 at 15.30.28.png


Integrate with your web form

The way you implement this will depend on which content management system (CMS) and front-end language you may use (React, Angular, HTML5...).

The POST request to the connector may be implemented directly on the front-end side using, for example, axios or JS fetch API.

Below is an example using Fetch:


/*
const formData = {
    "name":"John Doe",
    "email":"john@doe.com",
    "description":"Hello"    
}
*/

function createLead(formData){
    var myHeaders = new Headers();
    myHeaders.append("Content-Type", "application/json");

    var raw = JSON.stringify(formData);

    var requestOptions = {
      method: 'POST',
      headers: myHeaders,
      body: raw,
      redirect: 'follow'
    };

    fetch("http://localhost:8081/crm/lead/create", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));
}

However, to prevent exposing the connector to the public, we would recommend implementing it on the back-end side, in the existing function that already handles your form.


Issues

For more details about the code and issues, please check out our github repository.


Custom gateway and connectors

In need of inter-connecting systems to the cloud?

Feel free to contact us.