Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Webhooks - Create a lead

Naroči se

Get notified when there's activity on this post

This question has been flagged
webhookwebhooks
1 Odgovori
4801 Prikazi
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
Opusti
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
Opusti
Wombat
Avtor

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!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
webhook GET support?
webhooks
Avatar
0
jan. 25
1503
Webhooks - request.get_http_params() Solved
webhooks
Avatar
Avatar
1
jul. 24
2679
Webhooks NameError: name 'request' is not defined Solved
webhook
Avatar
Avatar
Avatar
2
jul. 24
3701
Is a webhook the best way to send data to a URL outside Odoo?
webhook
Avatar
1
dec. 22
4190
Error 500 Webhooks
saas webhook
Avatar
Avatar
Avatar
2
avg. 24
2287
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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