Prevent Double Sending in Smartlead CRM

Describe the problem/error/question

Hi, I’m new to n8n and need some help with a workflow I’m trying to implement. I want to prevent sending content to leads more than once if they have been stored in the database for less than 30 days. The leads will initially be sent from Clay, passed through a Webhook, and then stored in a pSQL table.

Here’s what I want the workflow to do:

  • Check the number of days a lead has been in the database
  • If a lead has been in the database (Smartlead/Instantly) for more than 30 days, delete it

Could anyone provide guidance on how to accomplish this? Any help would be greatly appreciated. Thank you!

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

n8n version: 1.19.0
Database: PSQL

Hi @florymay, welcome to the community!

Perhaps you can confirm where exactly you’re having trouble here? Based on your description it seems you’re mostly wondering how to work with the database using n8n, is this correct?

  • Check the number of days a lead has been in the database

This should be doable by running a query such as this (where created_at is the creation date of your lead and leads is your table name):

SELECT
  id,
  EXTRACT(
    DAY FROM NOW() - created_at
  ) AS lead_age
FROM
  leads;

This will return the id field of your leads along with their age, but you can of course also query other or additional fields you need (like the email of a lead):

  • If a lead has been in the database (Smartlead/Instantly) for more than 30 days, delete it

In n8n this requires two more nodes:

  1. An If node to check if a lead is older than 30 days (or not)
  2. Another PostgreSQL node handling the actual deletion

In a workflow this could like so:

Hope this helps! Keep in mind that I’ve created this using my own test data, your data structure is likely different and you’d need to adjust the SQL queries accordingly.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.