How to create CRM leads in Odoo using Zapier and API integration?

I’m stuck trying to set up a custom Zapier integration with Odoo CRM. I want to create new leads from Facebook Ads data, but the pre-built automation doesn’t include all the fields I need (like Campaign, Source, and Notes).

I’ve decided to use webhooks for more flexibility, but I’m having trouble figuring out the API. I managed to authenticate using the ‘/web/session/authenticate’ endpoint, but I’m lost on how to actually create a lead.

Here’s what I’ve got so far:

auth_data = {
    'jsonrpc': '2.0',
    'params': {
        'db': 'my_database',
        'login': '[email protected]',
        'password': 'secret_password'
    }
}

Can anyone help me figure out the next steps? What endpoint and parameters do I need to use to create a new lead in Odoo CRM? Any tips or code examples would be super helpful!

I’ve actually been through a similar process recently, and I can share what worked for me. After authentication, you’ll want to use the ‘/web/dataset/call_kw’ endpoint to create a new lead. Here’s a basic example of what the payload might look like:

create_lead_data = {
    'jsonrpc': '2.0',
    'method': 'call',
    'params': {
        'model': 'crm.lead',
        'method': 'create',
        'args': [{
            'name': 'Lead from Facebook Ad',
            'type': 'lead',
            'email_from': '[email protected]',
            'description': 'Notes from Facebook Ad',
            'medium_id': 1,  # ID for 'Facebook' medium
            'source_id': 2,  # ID for your custom source
            'campaign_id': 3,  # ID for your campaign
        }],
        'kwargs': {}
    }
}

You’ll need to adjust the field names and values to match your specific Odoo setup. Also, make sure to include the session_id from your authentication response in the cookies when making this request.

One tricky part was figuring out the correct IDs for things like medium, source, and campaign. I ended up creating a separate API call to fetch these first. It took some trial and error, but it’s working smoothly now. Let me know if you need any more details!

Having implemented a similar integration, I can offer some insights. After authentication, you’ll need to use the ‘/web/dataset/call_kw’ endpoint for creating leads. The payload structure is crucial. Ensure you’re passing the correct model (‘crm.lead’) and method (‘create’).

For the lead data, include essential fields like ‘name’, ‘type’, ‘email_from’, and any custom fields you’ve set up. You mentioned Campaign, Source, and Notes - these can be mapped to ‘campaign_id’, ‘source_id’, and ‘description’ respectively.

A common pitfall is handling relational fields. For ‘campaign_id’, ‘source_id’, etc., you need to pass the database ID, not the name. Consider fetching these IDs beforehand or storing them in your Zapier setup.

Remember to include the session_id from your authentication response in the request cookies. This step is often overlooked but is critical for maintaining the session.

Lastly, thorough testing is key. Start with a minimal set of fields and gradually add more to isolate any issues.

hey alex, i’ve done this before. after auth, use ‘/web/dataset/call_kw’ endpoint. payload should look like:

{
  'jsonrpc': '2.0',
  'method': 'call',
  'params': {
    'model': 'crm.lead',
    'method': 'create',
    'args': [{
      'name': 'FB Lead',
      'type': 'lead',
      'email_from': '[email protected]',
      'description': 'Notes here'
    }],
    'kwargs': {}
  }
}

don’t forget to include session_id in cookies. good luck!