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

Webhooks - Create a lead

Subscriure's

Get notified when there's activity on this post

This question has been flagged
webhookwebhooks
1 Respondre
4755 Vistes
Avatar
Wombat

Now I am trying to create a lead via a webhook. In Automations Rules, I have selected the 

Model: "Lead/Opportunity"

Trigger: "On Webhook"

Target Record: "model.browse(int(payload.get('id')))"  I don't know what relevance that has to creating a new record...but anyway.. 

-------------

The execute code is:

try:

    data = request.get_json_data()

except:

data = str(request.get_http_params())


name = data['name']

phone = data['phone']

email = data['email']


env['crm.lead'].create({

    'name': name,

    'user_id': 2,

    'phone': phone,

    'email_from': email,

    'type': "opportunity"

})

-------------

The xml from postman is

{ "id": "1", "name": "fred", "phone": "04400440040", "email": "jon@example.com"}


Postman report a "500 Internal Server Error"

-------------

From the logs:

2024-07-11 08:47:41,214 715 WARNING cal odoo.addons.base_automation.models.base_automation: Webhook #1 failed with error:

Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/odoo/models.py", line 5851, in ensure_one

    _id, = self._ids

ValueError: not enough values to unpack (expected 1, got 0)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/odoo/tools/safe_eval.py", line 390, in safe_eval

    return unsafe_eval(c, globals_dict, locals_dict)

  File "ir.actions.server(487,)", line 10, in

  File "", line 2, in create

  File "/opt/odoosrc/17.0/odoo/odoo/api.py", line 414, in _model_create_multi

    return create(self, [arg])

  File "/opt/odoosrc/17.0/odoo/addons/crm_iap_enrich/models/crm_lead.py", line 43, in create

    leads = super(Lead, self).create(vals_list)

  File "", line 2, in create

  File "/opt/odoosrc/17.0/odoo/odoo/api.py", line 415, in _model_create_multi

    return create(self, arg)

  File "/opt/odoosrc/17.0/odoo/addons/crm/models/crm_lead.py", line 761, in create

    leads = super(Lead, self).create(vals_list)

  File "", line 2, in create

  File "/opt/odoosrc/17.0/odoo/odoo/api.py", line 415, in _model_create_multi

    return create(self, arg)

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 285, in create

    thread.sudo().message_post(subtype_id=subtype.id, author_id=self.env.user.partner_id.id)

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 2136, in message_post

    if self.env.user._is_public() and guest:

  File "/opt/odoosrc/17.0/odoo/odoo/addons/base/models/res_users.py", line 1156, in _is_public

    self.ensure_one()

  File "/opt/odoosrc/17.0/odoo/odoo/models.py", line 5854, in ensure_one

    raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: res.users()


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/addons/base_automation/models/base_automation.py", line 509, in _execute_webhook

    return self._process(record)

  File "/opt/odoosrc/17.0/odoo/addons/base_automation/models/base_automation.py", line 671, in _process

    action.with_context(**ctx).run()

  File "/opt/odoosrc/17.0/odoo/odoo/addons/base/models/ir_actions.py", line 941, in run

    res = runner(run_self, eval_context=eval_context)

  File "/opt/odoosrc/17.0/odoo/addons/website/models/ir_actions_server.py", line 61, in _run_action_code_multi

    res = super(ServerAction, self)._run_action_code_multi(eval_context)

  File "/opt/odoosrc/17.0/odoo/odoo/addons/base/models/ir_actions.py", line 771, in _run_action_code_multi

    safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True, filename=str(self))  # nocopy allows to return 'action'

  File "/opt/odoosrc/17.0/odoo/odoo/tools/safe_eval.py", line 404, in safe_eval

    raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))

ValueError: : "Expected singleton: res.users()" while evaluating

'try:\n    data = request.get_json_data()\nexcept:\n\tdata = str(request.get_http_params())\n\nname = data[\'name\']\nphone = data[\'phone\']\nemail = data[\'email\']\n\nenv[\'crm.lead\'].create({\n    \'name\': name,\n    \'user_id\': 2,\n    \'phone\': phone,\n    \'email_from\': email,\n    \'type\': "opportunity"\n})'


2024-07-11 08:47:41,247 715 ERROR cal odoo.http: Exception during request handling. 

Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/odoo/models.py", line 5851, in ensure_one

    _id, = self._ids

ValueError: not enough values to unpack (expected 1, got 0)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/opt/odoosrc/17.0/odoo/odoo/http.py", line 2189, in __call__

    response = request._serve_db()

  File "/opt/odoosrc/17.0/odoo/odoo/http.py", line 1764, in _serve_db

    return service_model.retrying(self._serve_ir_http, self.env)

  File "/opt/odoosrc/17.0/odoo/odoo/service/model.py", line 135, in retrying

    env.cr.flush()  # submit the changes to the database

  File "/opt/odoosrc/17.0/odoo/odoo/sql_db.py", line 138, in flush

    self.precommit.run()

  File "/opt/odoosrc/17.0/odoo/odoo/tools/misc.py", line 1224, in run

    func()

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 530, in _track_finalize

    tracking = records.with_context(context)._message_track(fnames, initial_values)

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 636, in _message_track

    record.message_post(

  File "/opt/odoosrc/17.0/odoo/addons/mail/models/mail_thread.py", line 2136, in message_post

    if self.env.user._is_public() and guest:

  File "/opt/odoosrc/17.0/odoo/odoo/addons/base/models/res_users.py", line 1156, in _is_public

    self.ensure_one()

  File "/opt/odoosrc/17.0/odoo/odoo/models.py", line 5854, in ensure_one

    raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: res.users()

2024-07-11 08:47:41,248 715 INFO cal werkzeug: 127.0.0.1 - - [11/Jul/2024 08:47:41] "POST /web/hook/90b41425-8632-405d-b9a3-2e3f4a21fb5c HTTP/1.1" 500 - 83 0.047 0.137

-------------

I don't understand the "singleton" error as there is only one record being created and one user id supplied and no lists or arrays.


0
Avatar
Descartar
info@webdevelop.nl

Which fields do you need to map for a new opportunity?


Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

Hi,
See the method explained here: https://www.youtube.com/watch?v=D3urHJ9rB2o

Thanks 

0
Avatar
Descartar
Wombat
Autor

Perfect. Thank you Niyas.

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
Related Posts Respostes Vistes Activitat
webhook GET support?
webhooks
Avatar
0
de gen. 25
1474
Webhooks - request.get_http_params() Solved
webhooks
Avatar
Avatar
1
de jul. 24
2642
Webhooks NameError: name 'request' is not defined Solved
webhook
Avatar
Avatar
Avatar
2
de jul. 24
3674
Is a webhook the best way to send data to a URL outside Odoo?
webhook
Avatar
1
de des. 22
4175
Error 500 Webhooks
saas webhook
Avatar
Avatar
Avatar
2
d’ag. 24
2265
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