Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Webhooks - Create a lead

Subscribe

Get notified when there's activity on this post

This question has been flagged
webhookwebhooks
1 Reply
4783 Views
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
Discard
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
Discard
Wombat
Author

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!

Sign up
Related Posts Replies Views Activity
webhook GET support?
webhooks
Avatar
0
Jan 25
1493
Webhooks - request.get_http_params() Solved
webhooks
Avatar
Avatar
1
Jul 24
2668
Webhooks NameError: name 'request' is not defined Solved
webhook
Avatar
Avatar
Avatar
2
Jul 24
3695
Is a webhook the best way to send data to a URL outside Odoo?
webhook
Avatar
1
Dec 22
4189
Error 500 Webhooks
saas webhook
Avatar
Avatar
Avatar
2
Aug 24
2286
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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