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.
PermalinkIntroduction
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.
PermalinkWhat are we making?
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:
Capture form data
Check if the company exists in Twenty CRM
Create or update the company record
Create a new person record
Link the person to the company
Send a notification to the sales team
PermalinkPrerequisites Setup
PermalinkRequired Tools
Twenty CRM Account
Sign up at twenty.com
Ensure you have admin access
create a web hook.
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
PermalinkAuthentication Configuration
Step 1: Generate Twenty CRM API Token
Log into Twenty CRM
Navigate to Settings โ Developer mode toggle โ API Tokens
Click "Create New Token"
Name your token (e.g., "n8n Integration")
Copy the generated token immediately
PermalinkBuilding the Integration Workflow
PermalinkStep 1: Create the Workflow
In n8n, click "New Workflow"
Name it "Website Lead Capture"
PermalinkStep 2: Configure Webhook Trigger
- Add a Webhook node
Configure settings:
{
"method": "POST",
"path": "/lead-capture",
"response": "immediate"
}
Copy the generated webhook URL from Twenty settings.
PermalinkStep 3: Add Data Transformation
- 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
PermalinkStep 4: Company Search/Create
Add Twenty CRM node
Configure operation:
jsonCopy{ "resource": "company", "operation": "upsert", "matchFields": ["domain"], "data": { "name": "={{$node.Function.json.company.name}}", "domain": "={{$node.Function.json.company.domain}}" } }
PermalinkStep 5: Create Person Record
Add another Twenty CRM node
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}}" } }
PermalinkUsing AI to Enhance Your Integration
PermalinkGenerating API Requests with ChatGPT or Gemini
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"
}
PermalinkDebugging with AI
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.
PermalinkTroubleshooting and Best Practices
PermalinkCommon Issues and Solutions
Authentication Errors
Check API token expiration
Verify token permissions
Ensure proper token format in headers
Data Mapping Issues
Validate field names match exactly
Check for required fields
Verify data types (string, number, etc.)
Webhook Problems
Confirm webhook URL is correct
Check if n8n is running
Verify form submission method
PermalinkConclusion
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!