When contact added to Mautic from n8n emails sent twice or more

Hello, I hope everyone is feeling great.

When I update a contact, update contact campaign or segment with the Mautic node the emails are sent several times as if the contact is added repeatedly to the campaign.

I have tried adding the contact through segments and directly into the campaign and the behavior is the same. And when I check the profile of the contact in Mautic the logs shows that the campaign ran only once.

This only happens when I use Mautic with n8n as I have other campaigns running and this issue is not happening.

This is my workflow:

{
  "nodes": [
    {
      "parameters": {
        "operation": "getAll",
        "limit": 1,
        "options": {
          "search": "={{$node[\"Email\"].json[\"text\"]}}",
          "minimal": true
        }
      },
      "name": "Buscar el contacto",
      "type": "n8n-nodes-base.mautic",
      "typeVersion": 1,
      "position": [
        1050,
        -200
      ],
      "credentials": {
        "mauticApi": {
          "id": "6",
          "name": "Mautic Login n8n"
        }
      }
    },
    {
      "parameters": {
        "id": "5bec208e327e1704762fdc28"
      },
      "name": "Mover a retoques",
      "type": "n8n-nodes-base.trelloTrigger",
      "typeVersion": 1,
      "position": [
        200,
        50
      ],
      "webhookId": "45ca3332-1718-4fbe-9a3e-078d6f772f8a",
      "credentials": {
        "trelloApi": {
          "id": "1",
          "name": "Trello GDP"
        }
      }
    },
    {
      "parameters": {
        "operation": "get",
        "id": "={{$node[\"Mover a retoques\"].json[\"action\"][\"data\"][\"card\"][\"id\"]}}",
        "additionalFields": {
          "customFieldItems": true
        }
      },
      "name": "Buscar tarjeta",
      "type": "n8n-nodes-base.trello",
      "typeVersion": 1,
      "position": [
        400,
        50
      ],
      "credentials": {
        "trelloApi": {
          "id": "1",
          "name": "Trello GDP"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Retoque\"].json[\"checked\"]}}",
              "value2": "true"
            },
            {
              "value1": "={{$node[\"Mover a retoques\"].json[\"action\"][\"data\"][\"listBefore\"][\"name\"]}}",
              "operation": "notEqual",
              "value2": "={{$node[\"Mover a retoques\"].json[\"action\"][\"data\"][\"listAfter\"][\"name\"]}}"
            },
            {
              "value1": "={{$node[\"Mover a retoques\"].json[\"action\"][\"data\"][\"listBefore\"][\"name\"]}}",
              "operation": "notEqual",
              "value2": "Retoque"
            }
          ]
        }
      },
      "name": "Retoque Check",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        850,
        -100
      ]
    },
    {
      "parameters": {
        "functionCode": "//Retoque\nitem = item.customFieldItems.find(field => field.id == '6167499912604c42c3cccba8').value;\nreturn item;\n"
      },
      "name": "Retoque",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        650,
        -100
      ],
      "alwaysOutputData": false,
      "continueOnFail": true
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1050,
        0
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "contactId": "={{$node[\"Buscar el contacto\"].json[\"id\"]}}",
        "updateFields": {
          "customFieldsUi": {
            "customFieldValues": [
              {
                "fieldId": "album",
                "fieldValue": "={{$node[\"Album\"].json[\"text\"]}}"
              },
              {
                "fieldId": "estudio_o_exterior",
                "fieldValue": "={{$node[\"Estudio o Exterior\"].json[\"text\"]}}"
              }
            ]
          },
          "tags": "=retoque"
        },
        "options": {}
      },
      "name": "Actualizar contacto",
      "type": "n8n-nodes-base.mautic",
      "typeVersion": 1,
      "position": [
        1250,
        -200
      ],
      "credentials": {
        "mauticApi": {
          "id": "6",
          "name": "Mautic Login n8n"
        }
      }
    }
  ],
  "connections": {
    "Buscar el contacto": {
      "main": [
        [
          {
            "node": "Actualizar contacto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mover a retoques": {
      "main": [
        [
          {
            "node": "Buscar tarjeta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buscar tarjeta": {
      "main": [
        [
          {
            "node": "Retoque",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retoque Check": {
      "main": [
        [
          {
            "node": "Buscar el contacto",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retoque": {
      "main": [
        [
          {
            "node": "Retoque Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

How are you triggering the workflow? Is it possible that the workflow executes multiple times hence the various emails?

It’s triggered when I move a card to a specific Trello list. But before sending the info to Mautic the workflow has an if node.

Is it possible that the if node it’s not filtering the data correctly? You can check the executions tab and see what each run did. That way, you can discard that posiblity.

I checked the executions and the workflow ran 5 times.

Any reasons why this could be happening?

I found the problem. I have some automations on my board with Buttler whenever a card is move to the list I’m trying to use and this updates the card on some fields. I deactivated the automations and the workflow runs as expected.

Now I need to figure out how to run these rules after the card is move and not at the same time.

Thanks.

3 Likes

Hey @zerog,

I did something very similar with Trello. I don’t have the workflow with me, but I used the Trello Trigger node to start the workflow. I added an IF node to check if the card moved from board A to board B, and continued the workflow only if this condition was met.

I have not used Buttler, but can it make API calls? If so, you can create a workflow with the Webhook node. Buttler can send a request to that webhook URL to trigger the workflow in n8n.

Hope this helps :slight_smile:

Thank you @harshil1712 I did as you stated and it worked great

1 Like

Perfect! I am glad it worked out :tada: