Guide to Integrating Twenty CRM with Marketing Automation tool n8n.

Guide to Integrating Twenty CRM with Marketing Automation tool n8n.

ยท

4 min read

Hello again, folks! We meet once more. I know I've been writing a lot about open-source applications lately, but why not? I'm really enjoying using them in my daily life. As you've already seen from the blog title, let's dive in without wasting any time.

Introduction

This guide will walk you through automating lead capture from website forms directly into Twenty CRM using n8n. By the end of this guide, you'll have a fully functional automation that captures leads from your website and creates new records in Twenty CRM, complete with custom field mapping and error handling.

If you don't know how to self-host Twenty CRM, please visit my previous blog. In that blog, I guide you on how to self-host Twenty CRM in minutes.

Our example scenario: A marketing team wants to automatically capture leads from their website's contact form and create new company and person records in Twenty CRM. When a form is submitted, the automation will:

  1. Capture form data

  2. Check if the company exists in Twenty CRM

  3. Create or update the company record

  4. Create a new person record

  5. Link the person to the company

  6. Send a notification to the sales team

  1. Twenty CRM Account

    • Sign up at twenty.com

    • Ensure you have admin access

    • create a web hook.

  2. n8n Installation

    • Option A: Cloud Version

      • Visit n8n.io

      • Sign up for a cloud account

      • Select the Basic plan or higher

    • Option B: Self-hosted Version (optional)

      • Requires a server with Node.js & GitHub repo of n8n (optional)

      • Install using npm:

npm install n8n

Step 1: Generate Twenty CRM API Token

  1. Log into Twenty CRM

  2. Navigate to Settings โ†’ Developer mode toggle โ†’ API Tokens

  3. Click "Create New Token"

  4. Name your token (e.g., "n8n Integration")

Copy the generated token immediately

  1. In n8n, click "New Workflow"

  2. Name it "Website Lead Capture"

  1. Add a Webhook node

Configure settings:

{
  "method": "POST",
  "path": "/lead-capture",
  "response": "immediate"
}

Copy the generated webhook URL from Twenty settings.

  • Add a Function node

Use this code to format the data:

javascriptCopyreturn {
  json: {
    company: {
      name: items[0].json.company_name,
      domain: items[0].json.company_name.toLowerCase().replace(/[^a-z0-9]/g, '') + '.com'
    },
    person: {
      firstName: items[0].json.first_name,
      lastName: items[0].json.last_name,
      email: items[0].json.email,
      phone: items[0].json.phone || ''
    }
  }
};

The above json code will do the formation on twenty crm

  1. Add Twenty CRM node

  2. Configure operation:

     jsonCopy{
       "resource": "company",
       "operation": "upsert",
       "matchFields": ["domain"],
       "data": {
         "name": "={{$node.Function.json.company.name}}",
         "domain": "={{$node.Function.json.company.domain}}"
       }
     }
    
    1. Add another Twenty CRM node

    2. Configure settings:

       jsonCopy{
         "resource": "person",
         "operation": "create",
         "data": {
           "firstName": "={{$node.Function.json.person.firstName}}",
           "lastName": "={{$node.Function.json.person.lastName}}",
           "email": "={{$node.Function.json.person.email}}",
           "phone": "={{$node.Function.json.person.phone}}",
           "companyId": "={{$node.TwentyCRM1.json.id}}"
         }
       }
      

Use this prompt template for ChatGPT to generate API requests:

    CopyI need to create an API request for Twenty CRM to [describe action].
    My data structure is:
    [paste your data structure]

    Please provide:
    1. The endpoint URL
    2. Request method
    3. Headers needed
    4. Complete request body in JSON
    5. Example response

Example Usage:

    CopyHuman: I need to create an API request for Twenty CRM to create a new company.
    My data structure is:
    {
      "name": "Acme Corp",
      "domain": "acmecorp.com"
    }

    ChatGPT: Here's the API request format:

    Endpoint: https://[workspace].twenty.com/api/v1/companies
    Method: POST
    Headers:
    - Authorization: Bearer <your_api_token>
    - Content-Type: application/json

    Request Body:
    {
      "name": "Acme Corp",
      "domain": "acmecorp.com"
    }

    Expected Response:
    {
      "id": "12345",
      "name": "Acme Corp",
      "domain": "acmecorp.com",
      "createdAt": "2024-10-26T10:00:00Z"
    }

When encountering errors, format your question to AI like this:

    CopyError Context:
    1. What I'm trying to do: [action]
    2. Error message: [error]
    3. Current configuration: [config]

    Please help me:
    1. Understand the error
    2. Identify potential causes
    3. Suggest solutions

Now your n8n template should work without any errors. Congratulations on reaching this point! If you encounter any issues, please refer to the troubleshooting guide.

  1. Authentication Errors

    • Check API token expiration

    • Verify token permissions

    • Ensure proper token format in headers

  2. Data Mapping Issues

    • Validate field names match exactly

    • Check for required fields

    • Verify data types (string, number, etc.)

  3. Webhook Problems

    • Confirm webhook URL is correct

    • Check if n8n is running

    • Verify form submission method

In this blog, you've learned how to use n8n workflows to automate tasks with Twenty CRM. You can also self-host Twenty and n8n on a cloud or local server. I've written a blog about it, so please check it out on my profile. If you enjoyed the post or learned something new, please like and follow me. Thanks, and see you next time!

Did you find this article valuable?

Support K5LO7H's Blog by becoming a sponsor. Any amount is appreciated!