API Endpoints
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The OdooConnectorAPI is a RESTful interface built with FastAPI that serves as a bridge between external applications and an Odoo ERP instance. Its primary purpose is to abstract the complexity of Odoo's RPC (Remote Procedure Call) mechanism into standard HTTP endpoints, enabling asynchronous communication with Odoo models.
Sources: README.md:3-5, app/main.py:1-6
The API manages connection state via the odoorpc library and relies on environment-based configuration for authentication and server targeting. This architecture allows the API to be deployed in containerized environments like Docker or Kubernetes while maintaining connectivity to either local or remote Odoo databases.
Sources: app/main.py:9-12, README.md:7-11
Endpoint Architecture and Flow
The application logic follows a request-response cycle where the FastAPI application authenticates against the Odoo server for each relevant data request. The following diagram illustrates the typical data flow when an external client requests Odoo data through the connector.
This diagram shows the sequence of events for retrieving partner information from the Odoo backend.
Sources: app/main.py:24-40
Defined Endpoints
The API currently exposes the following HTTP endpoints for system health checks and data retrieval.
Root Endpoint
The root endpoint provides a simple connectivity test for the API itself, independent of the Odoo backend.
- Path:
/ - Method:
GET - Description: Returns a greeting message to verify the FastAPI service is running.
Sources: app/main.py:16-20
Partner Retrieval Endpoint
This endpoint interacts with the Odoo res.partner model to fetch specific contact information.
- Path:
/get/partners - Method:
GET - Logic:
- Initializes an
odoorpc.ODOOinstance using configured environment variables. - Attempts a login to the specified Odoo database.
- Performs a search for all partner records.
- Reads the
nameandemailfields for the discovered records. - Logs out and returns the data or an RPC error.
- Initializes an
Sources: app/main.py:23-40
| Endpoint | Method | Response Key | Data Source (Odoo Model) | Fields Retrieved |
|---|---|---|---|---|
/ | GET | message | N/A | N/A |
/get/partners | GET | partners | res.partner | name, email |
Sources: app/main.py:18-39
Configuration and Environment
The behavior of the API endpoints is strictly governed by environment variables. These variables are required for the odoorpc client to establish a valid session.
Connection Parameters
The API uses the following variables to define the target Odoo instance:
| Variable | Description | Default Value |
|---|---|---|
ODOO_URL | Hostname/URL of the Odoo server | localhost |
ODOO_DB | Name of the Odoo database | mydb |
ODOO_USERNAME | Login username (admin access) | admin |
ODOO_PASSWORD | Login password | admin |
Sources: app/main.py:9-12, charts/odooconnectorapi/values.yaml:18-22
Deployment Integration
In production environments, these variables are injected into the container via Docker Compose or Kubernetes Deployment manifests.
# Example from Kubernetes deployment
env:
- name: ODOO_URL
value: {{ .Values.env.ODOO_URL }}
- name: ODOO_DB
value: {{ .Values.env.ODOO_DB }}
Sources: charts/odooconnectorapi/templates/deployment.yaml:14-19, docker-compose.yml:10-14
Error Handling
The API endpoints implement basic error handling for RPC-related failures. If the odoorpc login or environment access fails, the API catches the odoorpc.error.RPCError and returns the error details within the JSON response instead of crashing the service.
try:
odoo = odoorpc.ODOO(ODOO_URL, port=80)
odoo.login(ODOO_DB, ODOO_USERNAME, ODOO_PASSWORD)
except odoorpc.error.RPCError as err:
return {"error": err}
Sources: app/main.py:27-31
Conclusion
The API endpoints serve as a lightweight wrapper around Odoo's internal models. By utilizing FastAPI's asynchronous capabilities and the odoorpc library, the system provides a simplified interface for external services to consume Odoo data, specifically targeting the partner directory in its current implementation.