Security:
- This process grants Zapier all permissions of the user, therefore it is necessary to create a dedicated user with restricted capabilities for this connection.
Prerequisites:
- Your Zapier.com account
- Your account for the external lead generation service
- Lead Creator role on your MetricWise.net account
- MetricWise 18.0.61 or later
Steps:
- Login to your MetricWise server as the dedicated user
- User Menu > My Profile, Account Security tab
- API Keys > New API Key
- Reconfirm your password if prompted
- Name your key = Zapier
- Duration = 3 months
- Generate key
- Refer back to this tab for the following instructions
-
Login to Zapier: https://zapier.com/app/login
- Create a new Zap
- Set the Trigger to your external lead generation service.
- Set the Action to Code
- Setup
- Action event = Run Python
- Continue
- Configure
- Input Data > Add Value Set
- ODOO_API_KEY = copy from above
- ODOO_HOST = URL of your MetricWise server
- ODOO_USER = login of dedicated user
- field = /field (for each desired Field below)
- Code = copy from below
- Continue
- Test step
- Publish
- Input Data > Add Value Set
- Setup
Fields:
company_id |
Company name |
| description | Free form text |
| email_from | Customer email |
| name | Customer name |
| phone | Customer phone |
| source_id | Lead source name |
| zip | Customer zip |
Code:
from xmlrpc.client import ServerProxy
ODOO_API_KEY = input_data.pop('ODOO_API_KEY')
ODOO_DATABASE = input_data.pop('ODOO_DATABASE', 'odoo')
ODOO_HOST = input_data.pop('ODOO_HOST')
ODOO_USER = input_data.pop('ODOO_USER')
with ServerProxy(f"{ODOO_HOST}/xmlrpc/2/common") as common:
uid = common.authenticate(ODOO_DATABASE, ODOO_USER, ODOO_API_KEY, {})
with ServerProxy(f"{ODOO_HOST}/xmlrpc/2/object") as object:
for field, model in {
'company_id': 'res.company',
'source_id': 'utm.source',
}.items():
if name := input_data.pop(field, None):
if found := object.execute_kw(ODOO_DATABASE, uid, ODOO_API_KEY, model, 'search_read', [[('name', '=', name)], ['id']], {'limit': 1}):
input_data[field] = found[0]['id']
output = {
'id': object.execute_kw(ODOO_DATABASE, uid, ODOO_API_KEY, 'crm.lead', 'create', [[input_data]], {})
}
Comments
0 comments
Please sign in to leave a comment.