Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2018 มุมมอง

Hello,

I have an external website that has a contact form and I want to retrieve the details from that contact form on submission and send it to Odoo. Odoo's external API is for reading, searching ...etc ie from an Odoo database to any external tools. Is the reverse also possible with external API (ie from the website to Odoo) or if I can use Webhooks and how do I proceed to do that?

Thanks,



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello, 

There are two kind of solutions:

Solution 1: 

import xmlrpc.client

# Odoo XML-RPC parameters
url = 'http://your-odoo-instance'
db = 'database_name'
username = 'user'
password = 'password'

# Connect to Odoo XML-RPC server
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})

# Create a proxy object for the CRM module
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

# Create a lead in Odoo
lead_data = {
    'name': 'John Doe',
    'contact_name': 'John Doe',
    'email_from': 'john@example.com',
    'description': 'Interested in your products',
    # Add more fields as needed
}
lead_id = models.execute_kw(db, uid, password, 'crm.lead', 'create', [lead_data])

Solution 2: 

from odoo import http
from odoo.http import request

class ExternalFormController(http.Controller):
   
    @http.route('/your/endpoint', type='http', auth='public', methods=['POST'])
    def handle_contact_form(self, **post):
        # Extract data from the incoming request
        name = post.get('name')
        email = post.get('email')
        message = post.get('message')
       
        # Create a lead/contact in Odoo
        Lead = request.env['crm.lead']
        lead_vals = {
            'name': name,
            'contact_name': name,
            'email_from': email,
            'description': message,
            # Add more fields as needed
        }
        lead = Lead.create(lead_vals)
       
        # You may want to return a response to the external form indicating success or failure
        return "Success"  # Or you can return JSON/XML response
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Original project names via the API แก้ไขแล้ว
1
เม.ย. 25
762
2
ม.ค. 25
832
0
ก.ย. 24
4
0
ก.ย. 24
1174
1
มิ.ย. 24
1623