DEV Community

sateshcharan
sateshcharan

Posted on

🚀 Supercharge Your Marketing with TwentyCRM + n8n

twentycrm with n8n

If you're managing customer relationships, you need to check out TwentyCRM! I recently discovered it through oss.gg, and after years of using clunky traditional CRMs with limited flexibility, TwentyCRM has been a game-changer. It’s packed with modern integrations right out of the box, offering flexibility that feels like a night-and-day difference.

But here’s where it gets really exciting—what if you could automate your marketing tasks, email campaigns, or even perform sentiment analysis using tools like n8n? With TwentyCRM and n8n, you can! Let’s dive in to see how it’s done. 🧠✨

twentycrm banner

TL;DR:

From "Self hosting with modified docker files" section:

  • Set up .env file with necessary environment variables.
  • Use the code for docker-compose.yml and run:
docker compose up -d
Enter fullscreen mode Exit fullscreen mode
  • Login to your applications:
    • Generate API keys for CRUD operations in TwentyCRM, save the credentials in n8n, and use them with the HTTP Request module in n8n.
    • Set up a Webhook trigger in n8n for event-driven communication if needed, and save the generated URL in TwentyCRM.
  • Build, test, and deploy your workflow to automate your processes seamlessly.

🧩 Why Integrate TwentyCRM with n8n?

TwentyCRM provides a solid, modern CRM foundation, and when integrated with automation tools like n8n, it eliminates repetitive tasks, boosts productivity, and expands functionality by integrating with hundreds of modules.
twentycrm feedback
Visit TwentyCRM to know more
n8n integrations
Visit n8n to know more

🖥️ System Requirements

Managed Environment with Official Support

  • No requirements; all resources are handled by the service provider

Self Hosting

  • RAM: A minimum of 2GB is recommended to prevent crashes due to insufficient memory.-
  • Docker & Docker Compose: Ensure both are installed and up-to-date.

⚙️ Setting Up the Environment
There are two options for setting up TwentyCRM and n8n:

☁️Managed Environment with Official Support
TwentyCRM and n8n offer managed services that are super easy to set up and affordable. If you're looking for a hassle-free start, this option would suit you best

homepage of twentycrm & n8n

  • Visit the websites of TwentyCRM and n8n.
  • Click “Sign Up” and register.
  • Upon successful registration you'll be able to login.

🏠Self-Hosting Setup
If you prefer self-hosting, TwentyCRM and n8n have open-source versions that you can install with limited features:

🖥️💾Self Hosting with Official docker-compose files
twentycrm one click docker compose

TwentyCRM offers a convenient One-line script:
From your terminal, run:

  • Download the docker-compose.yml file:
bash <(curl -sL https://git.new/20)
Enter fullscreen mode Exit fullscreen mode
  • Launch TwentyCRM Containers
cd twentycrm
docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

You can then access TwentyCRM by opening: http://localhost:3000

  • Create volume for n8n persistence
docker volume create n8n_data
Enter fullscreen mode Exit fullscreen mode
  • Start n8n docker container
docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
Enter fullscreen mode Exit fullscreen mode

This command will download all required n8n images and start your container, exposed on port 5678. To save your work between container restarts, it also mounts a docker volume, n8n_data, to persist your data locally.

You can then access n8n by opening: http://localhost:5678

🖥️🤖Self Hosting with modified docker-compose files(⚠️ Advisable only for advanced users)
Alternatively, you can leverage AI to generate a combined docker-compose.yml file by merging individual files into a single container setup. This approach simplifies troubleshooting and streamlines networking between containers, making your workflow much easier to manage.

version: "3.9"
name: twenty

services:
  change-vol-ownership:
    image: ubuntu
    user: root
    volumes:
      - server-local-data:/tmp/server-local-data
      - docker-data:/tmp/docker-data
    command: >
      bash -c "
      chown -R 1000:1000 /tmp/server-local-data
      && chown -R 1000:1000 /tmp/docker-data"

  server:
    image: twentycrm/twenty:${TAG}
    volumes:
      - server-local-data:/app/packages/twenty-server/${STORAGE_LOCAL_PATH:-.local-storage}
      - docker-data:/app/docker-data
    ports:
      - "3000:3000"
    mem_limit: 2g  # Memory limit for standalone Docker Compose setup

    environment:
      PORT: 3000
      PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default
      SERVER_URL: ${SERVER_URL}
      FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
      REDIS_PORT: ${REDIS_PORT:-6379}
      REDIS_HOST: ${REDIS_HOST:-redis}

      ENABLE_DB_MIGRATIONS: "true"

      SIGN_IN_PREFILLED: ${SIGN_IN_PREFILLED}
      STORAGE_TYPE: ${STORAGE_TYPE}
      STORAGE_S3_REGION: ${STORAGE_S3_REGION}
      STORAGE_S3_NAME: ${STORAGE_S3_NAME}
      STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}

      ACCESS_TOKEN_SECRET: ${ACCESS_TOKEN_SECRET}
      LOGIN_TOKEN_SECRET: ${LOGIN_TOKEN_SECRET}
      REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
      FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
    depends_on:
      change-vol-ownership:
        condition: service_completed_successfully
      db:
        condition: service_healthy
    healthcheck:
      test: curl --fail http://localhost:3000/healthz
      interval: 5s
      timeout: 5s
      retries: 10
    restart: always   

  worker:
    image: twentycrm/twenty:${TAG}
    command: ["yarn", "worker:prod"]
    environment:
      PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default
      SERVER_URL: ${SERVER_URL}
      FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL}
      REDIS_PORT: ${REDIS_PORT:-6379}
      REDIS_HOST: ${REDIS_HOST:-redis}

      ENABLE_DB_MIGRATIONS: "false" # it already runs on the server

      STORAGE_TYPE: ${STORAGE_TYPE}
      STORAGE_S3_REGION: ${STORAGE_S3_REGION}
      STORAGE_S3_NAME: ${STORAGE_S3_NAME}
      STORAGE_S3_ENDPOINT: ${STORAGE_S3_ENDPOINT}

      ACCESS_TOKEN_SECRET: ${ACCESS_TOKEN_SECRET}
      LOGIN_TOKEN_SECRET: ${LOGIN_TOKEN_SECRET}
      REFRESH_TOKEN_SECRET: ${REFRESH_TOKEN_SECRET}
      FILE_TOKEN_SECRET: ${FILE_TOKEN_SECRET}
    depends_on:
      db:
        condition: service_healthy
      server:
        condition: service_healthy
    restart: always

  db:
    image: twentycrm/twenty-postgres:${TAG}
    volumes:
      - db-data:/bitnami/postgresql
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_ADMIN_PASSWORD}
    healthcheck:
      test: pg_isready -U twenty -d default
      interval: 5s
      timeout: 5s
      retries: 10
    restart: always

  redis:
    image: redis
    ports:
      - "6379:6379"
    restart: always

  n8n:
    image: docker.n8n.io/n8nio/n8n
    container_name: n8n.twenty
    ports:
      - "5678:5678"
    volumes:
      - ./n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
    restart: unless-stopped

volumes:
  docker-data:
  db-data:
  server-local-data:

Enter fullscreen mode Exit fullscreen mode
  • ⚠️before starting ensure that you have setup the environment variables correctly using TwentyCRM docs
  • Start the containers with docker compose up -d

login page for twentycrm & n8n in selfhosting

  • Now you should have working applications of TwentyCRM & n8n to which you must be able to login to.

⚡ Interacting with TwentyCRM
TwentyCRM provides APIs for CRUD operations in both REST and GraphQL formats, along with webhook support for event-driven integration.

  • When an event occurs, TwentyCRM will make a POST request to the configured webhook URL based on the permissions set.

  • The API endpoints are organized into Metadata and Core categories, allowing flexible access based on your needs.

  • API Access Based on Subscription Plans
    Some API endpoints are only accessible with a subscription plans. Here’s a breakdown of the accessible APIs for Free and Paid plans:

API Type Description Free Plan Access Paid Plan Access
Core API Access to customer data, records, etc. Restricted Full
Metadata API Access to account settings and configurations Full Full
Webhook Support Event-based triggers to external services Limited Full
GraphQL API Flexible data queries Restricted Full

The Webhook Support offer limited access on the Free plan, while the Paid plan provides full access, ideal for more complex workflows and automation tasks involving mutations.

Detailed docs can be found at TwentyCRM

twentycrm api playground
TwentyCRM also provides a playground like setup to test endpoint communication:

🛠️ Setting Up the Integration
Seamless integration primarily revolves around three key concepts. Let’s quickly explore these concepts and illustrate them with a simple workflow example.

1. Create Your TwentyCRM API Access

  • You’ll need an API key to enable communication between TwentyCRM and your automation tool.
  • Login to TwentyCRM and navigate to Account Settings > Developers > API & Webhooks.
  • Generate a New API Key with permissions to read customer data and update records as required.
  • Use the generated key in n8n's HTTP Request module header as follows:
Authorization: Bearer {API_KEY}
Enter fullscreen mode Exit fullscreen mode

twentycrm & n8n webhook apikey pages

2. Setup n8n Webhook endpoint

  • Create a new workflow in n8n and add a trigger, such as a Webhook, that listens for new customer events in TwentyCRM.
  • Set the webhook method to POST and copy the generated URL.
  • Paste the URL into the designated field for the webhook URL in TwentyCRM.
  • Remember to replace this URL with the production webhook URL once development is complete.

3. Access TwentyCRM data in n8n

  • Set up the HTTP Request node in n8n.
  • In this node, use the {API_KEY} generated in Step 1 to fetch customer details from TwentyCRM. [Image idea: Screenshot of n8n workflow canvas with a Webhook and HTTP Request node visible, illustrating the flow setup.]

🧠🤖 AI-Powered API Request Generation (for low and no-code devs)
You might be thinking, "But I don’t know how to write API requests." Don’t worry! Here’s where AI comes in.

GPT-based natural language processing tools can help you write API requests, even if you’re not a coder. You simply describe what your needs as prompts and AI generates the API request for you.

Here’s how we can leverage it:

- Step 1: Describe Your Request
Ask the AI with a prompt like, "Generate a cURL API request to fetch {example} data from TwentyCRM in n8n."

- Step 2: Use the Response
Copy and paste the response into n8n’s HTTP Request node using the Import cURL feature. Adjust any credentials or parameters as needed, and n8n will automatically set up the request for you.

import curl option in n8n

This approach streamlines API setup, making it easier to integrate various services into your workflows.
⚠️Do remember that AI may not always yield the desired result so use with caution.

🧑‍🏫 Using n8n to automate workflow with TwentyCRM

Image description

Workflow Overview
This workflow is triggered when a new order is created in Shopify. Then:

  • The order information is stored in TwentyCRM,
  • An invoice is created in Harvest and stored in Trello,
  • If the order value is above 50, an email with a discount coupon is sent to the customer and they are added to a MailChimp campaign for high-value customers; otherwise, only a "thank you" email is sent to the customer.

  • Step 1: Shopify Trigger
    Trigger: This workflow starts when a new order is created in Shopify.
    Details: The “Shopify Trigger” node listens for the orders/create event from Shopify, capturing essential details like customer information, order number, and order total.

  • Step 2: Extract Key Information (Set Fields)
    Purpose: This step formats the Shopify order details to make them easily accessible for downstream nodes.
    Details: The “Set Fields” node extracts relevant data, including:
    Customer’s first name, last name, email, and phone number.
    Order total, which is crucial for later decision-making steps.

  • Step 3: Store Customer Data in TwentyCRM
    Purpose: To create or update the customer’s information in TwentyCRM for centralized customer management.
    Details: The “TwentyCRM - Upsert Customer” node sends an HTTP request to TwentyCRM’s API to save the customer’s first name, last name, email, and phone number.(AI models can be used to write the required API requests)

  • Step 4: Generate an Invoice in Harvest
    Purpose: To automatically generate an invoice for the order in Harvest.
    Details: The “Harvest” node uses the customer’s information and order details to create an invoice with the specified currency and the order number as the purchase order reference.

  • Step 5: Log Order in Trello
    Purpose: To create a Trello card for tracking the order fulfillment process.
    Details: The “Trello” node generates a card with the order number and basic order information on a designated Trello list, allowing the team to manage tasks related to this order.

  • Step 6: Evaluate Order Value (IF - Order Value)
    Purpose: To determine if the order qualifies as a high-value purchase.
    Condition: The “IF - Order Value” node checks whether the order total exceeds 50. This decision directs the workflow to either send a coupon email or a basic “thank you” email.

  • Step 7A: Send High-Value Customer Coupon Email (If Order > 50)
    Purpose: To encourage repeat purchases for high-value customers.
    Details: If the order total is greater than 50, the “Gmail - Send Coupon Email” node sends an email containing a 15% discount coupon for the next purchase.

  • Step 7B: Add Customer to Mailchimp High-Value Campaign
    Purpose: To target high-value customers for future marketing campaigns.
    Details: After sending the coupon email, the “Mailchimp” node adds the customer to a Mailchimp list with a “high-order” tag, enabling personalized marketing campaigns.

  • Step 8: Send Thank You Email (If Order ≤ 50)
    Purpose: To acknowledge smaller orders with a personalized thank-you message.
    Details: If the order total is 50 or less, the “Gmail - Send Thank You Email” node sends a simple thank-you email to the customer.

🤝Show your support for these amazing projects
🌐TwentyCRM | ✨Star TwentyCRM on github | 📦TwentyCRM docs
🌐n8n | ✨Star n8n on github | 📦n8n docs

🎯 Exited to try? have a go at these workflows:

  • Creating automatic reminders when leads go cold 🔔
  • Scoring customer sentiment using AI analysis 🔍

Do you have any cool integration ideas or questions? Drop them in the comments! 👇 Let's brainstorm together!

footer image

Top comments (0)