Check data from 2 different parents

I have 2 email fields in each api, the api doesn’t have a webhook so I always have to get the same data. what I’m trying to do is, search all emails from an api, and check if the next api has all the emails, if not all, register only the ones that are missing.

This flow is to automatically register users who have registered on one platform, passing the data to the other platform.

I’m going to leave here the flow that I’ve already done some tests. and also the image of the flow.

{
  "nodes": [
    {
      "parameters": {
        "authentication": "headerAuth",
        "url": "={{$node[\"url_base_api1\"].json[\"url_principal\"]}}{{$json[\"url_buscar_todos_leads\"]}}",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        }
      },
      "name": "Buscar_todos_Leads1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        770,
        340
      ],
      "notesInFlow": true,
      "credentials": {
        "httpHeaderAuth": {
          "id": "8",
          "name": "token_curso_perfex"
        }
      },
      "continueOnFail": true,
      "notes": "buscar todos clientes perfex, curso de perfex crm"
    },
    {
      "parameters": {
        "functionCode": "// Based on:\n// https://docs.n8n.io/reference/javascript-code-snippets.html#_1-create-multiple-items-from-a-single-item\nreturn items[0].json.map(item => {\n  return {\n    json: item\n  }\n});\n"
      },
      "name": "Dividir_Leads1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        940,
        350
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [],
          "string": [
            {
              "value1": "={{$json[\"fields\"][\"all\"][\"email\"]}}",
              "value2": "={{$json[\"fields\"][\"all\"][\"email\"]}}\n\n{{$item(0).$node[\"Dividir_Leads1\"].json[\"email\"]}}"
            }
          ]
        },
        "combineOperation": "any"
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1290,
        370
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "url_principal",
              "value": "https://curso.px.engineteam.com.br/"
            }
          ]
        },
        "options": {}
      },
      "name": "url_base_api1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        380,
        330
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "url_buscar_todos_leads",
              "value": "api/leads"
            },
            {
              "name": "Adicionar_Lead",
              "value": "api/leads"
            },
            {
              "name": "Excluir_Lead",
              "value": "api/delete/leads/"
            },
            {
              "name": "Ver_todos_Leads",
              "value": "api/leads/"
            },
            {
              "name": "Atualizar_Leads",
              "value": "api/leads/"
            },
            {
              "name": "Buscar_informacao_Leads",
              "value": "api/leads/search/"
            }
          ]
        },
        "options": {}
      },
      "name": "url_Leads1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        580,
        330
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{$node[\"Set1\"].json[\"nome_tag\"]}}",
        "rules": {
          "rules": [
            {
              "value2": "faze04"
            },
            {
              "value2": "faze02",
              "output": 1
            },
            {
              "value2": "fase01",
              "output": 2
            },
            {
              "value2": "faze03",
              "output": 3
            }
          ]
        }
      },
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        1490,
        310
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "getAll",
        "returnAll": true,
        "options": {
          "search": "={{$item(0).$node[\"Dividir_Leads1\"].json[\"email\"]}}"
        }
      },
      "name": "Mautic",
      "type": "n8n-nodes-base.mautic",
      "typeVersion": 1,
      "position": [
        1130,
        180
      ],
      "credentials": {
        "mauticOAuth2Api": {
          "id": "9",
          "name": "Mautic account out2"
        }
      }
    }
  ],
  "connections": {
    "Buscar_todos_Leads1": {
      "main": [
        [
          {
            "node": "Dividir_Leads1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dividir_Leads1": {
      "main": [
        [
          {
            "node": "Mautic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "url_base_api1": {
      "main": [
        [
          {
            "node": "url_Leads1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "url_Leads1": {
      "main": [
        [
          {
            "node": "Buscar_todos_Leads1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mautic": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hey @egnine_team,

Thanks for sharing the workflow. You can use the Merge node with the Remove Key Matches mode. You can refer to this example that does something similar: Add only new records to Airtable

The Remove Key Matches mode will only return the emails that are not present. You can then add that email address to the API.

Hope this helps :slight_smile: