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

Webhooks - Create a lead

Odoberať

Get notified when there's activity on this post

This question has been flagged
webhookwebhooks
1 Odpoveď
4772 Zobrazenia
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
Zrušiť
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
Zrušiť
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!

Registrácia
Related Posts Replies Zobrazenia Aktivita
webhook GET support?
webhooks
Avatar
0
jan 25
1487
Webhooks - request.get_http_params() Solved
webhooks
Avatar
Avatar
1
júl 24
2658
Webhooks NameError: name 'request' is not defined Solved
webhook
Avatar
Avatar
Avatar
2
júl 24
3684
Is a webhook the best way to send data to a URL outside Odoo?
webhook
Avatar
1
dec 22
4187
Error 500 Webhooks
saas webhook
Avatar
Avatar
Avatar
2
aug 24
2284
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