Manipulating Data with If else Node

Good morning everyone, I’m not able to compare 2 values in the if else node, I need to compare all the data that returns from an api, and just get mine with the same “email” from another api, so update the data with reference to the ID of the other api.

I made 2 stream. one to register a user in the api and another to update that same user.

I’ll leave the stream I’m using here, I’ll also leave the data that returns in each search.

{
  "nodes": [
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "url_principal",
              "value": "https://curso.px.engineteam.com.br/"
            }
          ]
        },
        "options": {}
      },
      "name": "url_base_api",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1350,
        570
      ]
    },
    {
      "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/"
            },
            {
              "name": "modo_dados",
              "value": "="
            }
          ]
        },
        "options": {}
      },
      "name": "url_Leads",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1520,
        570
      ]
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "PUT",
        "url": "={{$node[\"url_base_api\"].json[\"url_principal\"]}}{{$node[\"url_Leads\"].json[\"Atualizar_Leads\"]}}{{$json[\"Id_leads_atulizar\"]}}",
        "options": {
          "useQueryString": false
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "company",
              "value": "enginenbn"
            }
          ]
        },
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "Atualizar_clientes",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        2270,
        760
      ],
      "notesInFlow": true,
      "executeOnce": true,
      "credentials": {
        "httpHeaderAuth": {
          "id": "8",
          "name": "token_curso_perfex"
        }
      },
      "continueOnFail": true,
      "notes": "Atualizar cliente pelo ID"
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Id_leads_atulizar"
            }
          ]
        },
        "options": {}
      },
      "name": "Id_leads_para_atualizar",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        2040,
        770
      ],
      "executeOnce": true
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "POST",
        "url": "={{$node[\"url_base_api\"].parameter[\"values\"][\"string\"][0][\"value\"]}}{{$items(\"url_Leads\")[0].json[\"url_buscar_todos_leads\"]}}",
        "options": {
          "useQueryString": false
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "source",
              "value": "1"
            },
            {
              "name": "status",
              "value": "2"
            },
            {
              "name": "name",
              "value": "={{$node[\"Definir_dados_mautic\"].json[\"Nome_contato\"]}}"
            },
            {
              "name": "email",
              "value": "={{$node[\"Definir_dados_mautic\"].json[\"email Cliente\"]}}"
            }
          ]
        },
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        }
      },
      "name": "Cadastrar_Lead_Id",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1730,
        570
      ],
      "notesInFlow": true,
      "executeOnce": true,
      "credentials": {
        "httpHeaderAuth": {
          "id": "8",
          "name": "token_curso_perfex"
        }
      },
      "continueOnFail": true,
      "notes": "Buscar o lead pelo ID"
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "url": "={{$node[\"url_base_api\"].parameter[\"values\"][\"string\"][0][\"value\"]}}{{$node[\"url_Leads\"].parameter[\"values\"][\"string\"][0][\"value\"]}}",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Content-Type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        }
      },
      "name": "Buscar_todos_Leads",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1370,
        760
      ],
      "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_Leads",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1560,
        770
      ]
    },
    {
      "parameters": {
        "events": [
          "mautic.lead_post_save_update"
        ]
      },
      "name": "Mautic Trigger1",
      "type": "n8n-nodes-base.mauticTrigger",
      "typeVersion": 1,
      "position": [
        660,
        780
      ],
      "webhookId": "f89441f3-45dc-4582-a915-c107c1bd75b0",
      "credentials": {
        "mauticApi": {
          "id": "10",
          "name": "Mautic account 2"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "id_cliente",
              "value": "={{$json[\"mautic.lead_post_save_update\"][0][\"contact\"][\"id\"]}}"
            },
            {
              "name": "Nome_contato",
              "value": "={{$json[\"mautic.lead_post_save_update\"][0][\"contact\"][\"fields\"][\"core\"][\"firstname\"][\"normalizedValue\"]}}"
            },
            {
              "name": "ID_TEG",
              "value": "={{$json[\"mautic.lead_post_save_update\"][0][\"contact\"][\"tags\"][0][\"id\"]}}"
            },
            {
              "name": "nome_tag",
              "value": "={{$json[\"mautic.lead_post_save_update\"][0][\"contact\"][\"tags\"][0][\"tag\"]}}"
            },
            {
              "name": "email Cliente",
              "value": "={{$json[\"mautic.lead_post_save_update\"][0][\"contact\"][\"fields\"][\"core\"][\"email\"][\"value\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        840,
        760
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [],
          "string": [
            {
              "value1": "={{$node[\"Set1\"].json[\"email Cliente\"]}}",
              "value2": "={{$node[\"Dividir_Leads\"].json[\"email\"]}}"
            }
          ]
        },
        "combineOperation": "any"
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1790,
        780
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "id_cliente",
              "value": "={{$node[\"Mautic_Trigger_novo\"].json[\"mautic.lead_post_save_new\"][0][\"contact\"][\"id\"]}}"
            },
            {
              "name": "Nome_contato",
              "value": "={{$json[\"mautic.lead_post_save_new\"][0][\"contact\"][\"fields\"][\"core\"][\"firstname\"][\"value\"]}}"
            },
            {
              "name": "ID_TEG",
              "value": "={{$json[\"mautic.lead_post_save_new\"][0][\"contact\"][\"tags\"][0][\"id\"]}}"
            },
            {
              "name": "nome_tag",
              "value": "={{$json[\"mautic.lead_post_save_new\"][0][\"contact\"][\"tags\"][0][\"tag\"]}}"
            },
            {
              "name": "email Cliente",
              "value": "={{$json[\"mautic.lead_post_save_new\"][0][\"contact\"][\"fields\"][\"core\"][\"email\"][\"value\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Definir_dados_mautic",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1170,
        570
      ]
    },
    {
      "parameters": {
        "events": [
          "mautic.lead_post_save_new"
        ]
      },
      "name": "Mautic_Trigger_novo",
      "type": "n8n-nodes-base.mauticTrigger",
      "typeVersion": 1,
      "position": [
        1000,
        570
      ],
      "webhookId": "9094cd62-d24e-452e-9a67-c3aa897a39ec",
      "credentials": {
        "mauticApi": {
          "id": "10",
          "name": "Mautic account 2"
        }
      }
    },
    {
      "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": [
        1000,
        760
      ]
    },
    {
      "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": [
        1200,
        760
      ]
    }
  ],
  "connections": {
    "url_base_api": {
      "main": [
        [
          {
            "node": "url_Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "url_Leads": {
      "main": [
        [
          {
            "node": "Cadastrar_Lead_Id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Id_leads_para_atualizar": {
      "main": [
        [
          {
            "node": "Atualizar_clientes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buscar_todos_Leads": {
      "main": [
        [
          {
            "node": "Dividir_Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dividir_Leads": {
      "main": [
        [
          {
            "node": "IF1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mautic Trigger1": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set1": {
      "main": [
        [
          {
            "node": "url_base_api1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF1": {
      "main": [
        [
          {
            "node": "Id_leads_para_atualizar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Definir_dados_mautic": {
      "main": [
        [
          {
            "node": "url_base_api",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mautic_Trigger_novo": {
      "main": [
        [
          {
            "node": "Definir_dados_mautic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "url_base_api1": {
      "main": [
        [
          {
            "node": "url_Leads1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "url_Leads1": {
      "main": [
        [
          {
            "node": "Buscar_todos_Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

data it returns from the other api.

[
  {
    "contact": {
      "isPublished": true,
      "dateAdded": "2021-11-05T20:32:04-03:00",
      "dateModified": "2021-11-06T07:49:40-03:00",
      "createdBy": null,
      "createdByUser": null,
      "modifiedBy": 1,
      "modifiedByUser": "Admin Mautic",
      "id": 607,
      "points": 0,
      "color": null,
      "fields": {
        "core": {
          "id_perfex": {
            "id": "44",
            "label": "id_perfex",
            "alias": "id_perfex",
            "type": "number",
            "group": "core",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:2:{s:9:\"roundmode\";s:1:\"3\";s:5:\"scale\";s:0:\"\";}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "title": {
            "id": "1",
            "label": "Title",
            "alias": "title",
            "type": "lookup",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:1:{s:4:\"list\";a:3:{i:0;s:2:\"Mr\";i:1;s:3:\"Mrs\";i:2;s:4:\"Miss\";}}",
            "default_value": null,
            "value": "engine",
            "normalizedValue": "engine"
          },
          "firstname": {
            "id": "2",
            "label": "First Name",
            "alias": "firstname",
            "type": "text",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "agthon",
            "normalizedValue": "agthon"
          },
          "lastname": {
            "id": "3",
            "label": "Last Name",
            "alias": "lastname",
            "type": "text",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "estevam",
            "normalizedValue": "estevam"
          },
          "company": {
            "id": "4",
            "label": "Primary company",
            "alias": "company",
            "type": "text",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": null,
            "normalizedValue": null
          },
          "position": {
            "id": "5",
            "label": "Position",
            "alias": "position",
            "type": "text",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "email": {
            "id": "6",
            "label": "Email",
            "alias": "email",
            "type": "email",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "[email protected]",
            "normalizedValue": "[email protected]"
          },
          "mobile": {
            "id": "7",
            "label": "Mobile",
            "alias": "mobile",
            "type": "tel",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "phone": {
            "id": "8",
            "label": "Phone",
            "alias": "phone",
            "type": "tel",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "points": {
            "id": "9",
            "label": "Points",
            "alias": "points",
            "type": "number",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": "0",
            "value": 0,
            "normalizedValue": 0
          },
          "fax": {
            "id": "10",
            "label": "Fax",
            "alias": "fax",
            "type": "tel",
            "group": "core",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "address1": {
            "id": "11",
            "label": "Address Line 1",
            "alias": "address1",
            "type": "text",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "address2": {
            "id": "12",
            "label": "Address Line 2",
            "alias": "address2",
            "type": "text",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "city": {
            "id": "13",
            "label": "City",
            "alias": "city",
            "type": "text",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "state": {
            "id": "14",
            "label": "State",
            "alias": "state",
            "type": "region",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "zipcode": {
            "id": "15",
            "label": "Zip Code",
            "alias": "zipcode",
            "type": "text",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "country": {
            "id": "16",
            "label": "Country",
            "alias": "country",
            "type": "country",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "preferred_locale": {
            "id": "17",
            "label": "Preferred Locale",
            "alias": "preferred_locale",
            "type": "locale",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "timezone": {
            "id": "18",
            "label": "Preferred Timezone",
            "alias": "timezone",
            "type": "timezone",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "last_active": {
            "id": "19",
            "label": "Date Last Active",
            "alias": "last_active",
            "type": "datetime",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "attribution_date": {
            "id": "20",
            "label": "Attribution Date",
            "alias": "attribution_date",
            "type": "datetime",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "attribution": {
            "id": "21",
            "label": "Attribution",
            "alias": "attribution",
            "type": "number",
            "group": "core",
            "object": "lead",
            "is_fixed": "1",
            "properties": "a:2:{s:9:\"roundmode\";i:4;s:5:\"scale\";i:2;}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "website": {
            "id": "22",
            "label": "Website",
            "alias": "website",
            "type": "url",
            "group": "core",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          }
        },
        "social": {
          "facebook": {
            "id": "23",
            "label": "Facebook",
            "alias": "facebook",
            "type": "text",
            "group": "social",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "foursquare": {
            "id": "24",
            "label": "Foursquare",
            "alias": "foursquare",
            "type": "text",
            "group": "social",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "instagram": {
            "id": "25",
            "label": "Instagram",
            "alias": "instagram",
            "type": "text",
            "group": "social",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "0",
            "normalizedValue": "0"
          },
          "linkedin": {
            "id": "26",
            "label": "LinkedIn",
            "alias": "linkedin",
            "type": "text",
            "group": "social",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "skype": {
            "id": "27",
            "label": "Skype",
            "alias": "skype",
            "type": "text",
            "group": "social",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          },
          "twitter": {
            "id": "28",
            "label": "Twitter",
            "alias": "twitter",
            "type": "text",
            "group": "social",
            "object": "lead",
            "is_fixed": "0",
            "properties": "a:0:{}",
            "default_value": null,
            "value": "",
            "normalizedValue": ""
          }
        },
        "personal": [],
        "professional": []
      },
      "lastActive": null,
      "owner": {
        "createdByUser": null,
        "modifiedByUser": "Admin Mautic",
        "id": 1,
        "username": "admin",
        "firstName": "Admin",
        "lastName": "Mautic"
      },
      "ipAddresses": [],
      "tags": [
        {
          "id": 2,
          "tag": "faze02"
        }
      ],
      "utmtags": [],
      "stage": null,
      "dateIdentified": "2021-11-05T20:32:04-03:00",
      "preferredProfileImage": "gravatar",
      "doNotContact": [],
      "frequencyRules": []
    },
    "timestamp": "2021-11-06T07:49:42-03:00"
  }
]

In the value 1 of the IF node, change the value to: {{$item(0).$node["Set1"].json["email Cliente"]}}

1 Like

that’s right, very good for the help