API Integrations with Odoo

APIs is the new industry buzzword going around when it comes to integrating two of more software systems. This Blog will attempt to give all Odoo stakeholders a good idea regarding API integration, whether it be business owners or the implementation SPOC.

 


 
What is an API?
An API is a connection key which connects two or more systems together. Using APIs one can ensure that two systems talk to each other. Now this is an incredibly layman definition of an API. If you wish to learn more on the technical points of an API, check this post here.
 
Why do we need an API?

Let’s use a practical example that you may come across if you’re implementing an Odoo system: You’re integrating a 3rd party e-Commerce system with Odoo with various functions, such as pushing an invoice into Odoo without opening your system.
Another example of an API use case, would be to send information to your shipping system from Odoo.
Technical users need to make note that Odoo provides an RPC endpoint (Namely XML RPC/2). You could use your favourite programming language to communicate with this end point.
In some cases, if Restful API is needed, then there are some 3rd party modules that provide a restful API. The second option would be to build your own using web controllers.
 
Difference Between Rest and RPC?
In layman terms, Rest is basic and therefore more popular. Compared to RPCs, it has more explicit verbs. This allows simplicity is calling functions through an API. For example, if you want to create a product, there is a route called product and if you send a request to this route, a product will be created.
In an RPC, you need to know the specific procedure names. For example, there will be a procedure name called: Create Product or Create Bill, etc. This essentially translates to the fact that you (or your developer) will need to know specific knowledge regarding the system to run commands on it.
Final Verdict: We can conclude with the statement that RPCs are more flexible but less intuitive than rest.
 
​How to use RPC API in Odoo?

API Setup:

  • First you need to set some server proxies to fetch some metadata. We basically need the models and then methods.
  • Model Name: Name of the model you wish to control in the Odoo DB
  • Method Name: Python functions used to control the Model
  • Once you authenticate successfully, you’ll receive a user ID which will be used in your transactions.
  • If needed, pass any python functions as a keyword argument if you wanted to add additional context.
  • Some methods repeated by an underscore can be used using XML RPC (Will be used by different methods).
  •  Ensure that the user modifying this information is in the database has all the access they need.

API Usage:

  • In the application, set up the parameters required. For example, the URL, data, username and password.
  • Fetch data and authenticate and the proceed to authenticate
  • Clean the data if needed by running any suitable functions.
  • You can manipulate and view this data to make sense of if needed.

 
Please check out the video at the top for an in-depth introduction to APIs. The video also shows a deeper example of creating an Invoice on a Sales Order using an external API. 

Odoo MES
Odoo's newest version is revisiting manufacturing with some big improvements applying a new concept known as MES (Manufacturing Execution System)