Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Issue with Creating Users in Odoo via XML-RPC from Express.js Backend

Subscriure's

Get notified when there's activity on this post

This question has been flagged
1325 Vistes
Avatar
Nolhan

Voici une version mise à jour de ton problème en anglais, incluant toutes les informations et les fichiers pertinents :

Subject: Error Creating Users in Odoo via XML-RPC from Express.js Backend


Hi,


I’m experiencing an issue when trying to create users in Odoo using the xml-rpc library in my Express.js backend. Here’s a detailed overview of my setup:


Setup

1. Environment

• Dockerized Application

• Odoo: version 18.0

• PostgreSQL: version 15

• Backend: Express.js (with xml-rpc library) with node:16

• Frontend: Next.js (not directly relevant to the issue)

• The Odoo database is correctly initialized using Docker, and there are no issues with the database setup.

2. Endpoints

• A GET route verifies the connection to Odoo via XML-RPC, and it works perfectly.

• A POST route attempts to create a user in Odoo by calling the create method of the res.users model.

3. The Problem

• When I send a POST request to create a user, I receive an error indicating that I am providing too many “positional arguments”.

• The error persists despite passing what I believe to be the correct payload.


Key Files


Below are the files relevant to my setup:


docker-compose.yml

services:
  postgres_db:
    image: postgres:15
    container_name: postgres_db
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
      POSTGRES_DB: xiptelecom
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init_postgres_odoo.sql:/docker-entrypoint-initdb.d/init_postgres_odoo.sql
    ports:
      - "5432:5432"
    restart: always

  odoo:
    image: odoo:18.0
    container_name: odoo
    depends_on:
      - postgres_db
    ports:
      - "8069:8069"
    volumes:
      - odoo-web-data:/var/lib/odoo
      - ./config:/etc/odoo
      - ./addons:/mnt/extra-addons
      - ./logs:/var/log/odoo
    environment:
      - HOST=postgres_db
      - USER=odoo_user
      - PASSWORD=odoo_password
    command: odoo -d odoo --db_user=odoo_user --db_password=odoo_password -i base
    restart: always

  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin4_container
    restart: always
    ports:
      - "5050:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@admin.com
      PGADMIN_DEFAULT_PASSWORD: admin
    volumes:
      - pgadmin_data:/var/lib/pgadmin

  backend:
    build:
      context: ./Backend
      dockerfile: Dockerfile
    container_name: backend
    command: "npm run dev"
    volumes:
      - ./Backend:/usr/src/app
    ports:
      - "1337:1337"
    depends_on:
      - postgres_db

  frontend:
    build:
      context: ./Frontend
      container_name: frontend
      command: "npm run dev"
      volumes:
        - ./Frontend:/app
      ports:
        - "3000:3000"
      depends_on:
        - backend

volumes:
  postgres_data:
  pgadmin_data:
  odoo-web-data:
  odoo-db-data:

server.js

const express = require('express');
const port = 1337;
const app = express();

app.use(express.json());

const { connectToOdoo, createUserInOdoo } = require('./odoo.js');

app.get('/api/test-odoo', async (req, res) => {
    try {
        await connectToOdoo();
        res.status(200).json({ message: 'Connexion à Odoo réussie !' });
    } catch (err) {
        res.status(500).json({ error: 'Connexion à Odoo échouée.', details: err.message });
    }
});

app.post('/create-user', async (req, res) => {
    const { name, email, login } = req.body;

    if (!name || !email || !login) {
        return res.status(400).json({ error: 'Tous les champs sont requis (name, email, login)' });
    }

    try {
        await connectToOdoo();
        const userId = await createUserInOdoo({ name, login, email });
        res.status(201).json({ message: 'Utilisateur créé avec succès dans Odoo', userId });
    } catch (err) {
        res.status(500).json({ error: 'Erreur lors de la création de l\'utilisateur dans Odoo', details: err.message });
    }
});

app.listen(port, () => console.log(`Le backend à démarré sur le port : ${port}`));

odoo.js

const Odoo = require('odoo-xmlrpc');

const odoo = new Odoo({
    url: 'http://odoo:8069',
    db: 'odoo',
    username: 'admin',
    password: 'admin',
});

const connectToOdoo = async () => {
    return new Promise((resolve, reject) => {
        odoo.connect((err) => {
            if (err) {
                reject(err);
            } else {
                resolve();
            }
        });
    });
};

const createUserInOdoo = async (userData) => {
    try {
        await connectToOdoo();
        const response = await new Promise((resolve, reject) => {
            odoo.execute_kw('res.users', 'create', [userData], (err, value) => {
                if (err) reject(err);
                else resolve(value);
            });
        });
        return response;
    } catch (err) {
        throw new Error(err);
    }
};

module.exports = { connectToOdoo, createUserInOdoo };

Request Sent from REST Client

POST http://localhost:1337/create-user
Content-Type: application/json

{
  "name": "Test User",
  "email": "testuser@example.com",
  "login": "testuser"
}

The error I receive :

HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 1973
ETag: W/"7b5-HnkxxuFqhmAddquOjPBhWEHKDTE"
Date: Mon, 27 Jan 2025 15:22:10 GMT
Connection: close

{
  "error": "Erreur lors de la création de l'utilisateur dans Odoo",
  "details": "Erreur lors de la création de l'utilisateur : Erreur lors de la création de l'utilisateur : XML-RPC fault: Traceback (most recent call last):\n  File \"/usr/lib/python3/dist-packages/odoo/addons/base/controllers/rpc.py\", line 161, in xmlrpc_2\n    response = self._xmlrpc(service)\n               ^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/addons/base/controllers/rpc.py\", line 139, in _xmlrpc\n    result = dispatch_rpc(service, method, params)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/http.py\", line 398, in dispatch_rpc\n    return dispatch(method, params)\n           ^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 39, in dispatch\n    res = execute_kw(db, uid, *params[3:])\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 61, in execute_kw\n    return execute(db, uid, obj, method, *args, **kw or {})\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 68, in execute\n    res = execute_cr(cr, uid, obj, method, *args, **kw)\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 52, in execute_cr\n    result = retrying(partial(odoo.api.call_kw, recs, method, args, kw), env)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/service/model.py\", line 137, in retrying\n    result = func()\n             ^^^^^^\n  File \"/usr/lib/python3/dist-packages/odoo/api.py\", line 517, in call_kw\n    result = getattr(recs, name)(*args, **kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nTypeError: create() takes 2 positional arguments but 4 were given\n"
}


Question


• Why does the create() method fail with a “positional arguments” error in this context?

• Could you provide guidance on the correct format for the create method in Odoo when using XML-RPC?

• Do I need to adjust the userData object structure to align with Odoo’s expectations?


Thank you in advance for any assistance!


0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now