Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
1335 Zobrazenia
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
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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