Match Two Datasets

I’m working on an n8n node that takes an inbound webhook POST and turns that into a HTTP POST to another service. This works fine, but I now need to build on it to check the inbound data against data pulled from an HTTP GET and return an ID if a match is found. I suspect the Merge node will do this, but I’m not sure. Here’s the sample webhook data:

[
   {
      "headers":{
         "content-type":"application/json; charset=utf-8"
      },
      "params":{
         
      },
      "query":{
         
      },
      "body":{
         "id":32,
         "name":"Mexico",
         "client_id":15,
         "client_name":"John the Plumber"
      }
   }
]

And here’s the HTTP GET data:

[
   [
      {
         "id":7,
         "name":"Canada",
         "server_policy":null,
         "workstation_policy":null,
         "alert_template":null,
         "client_name":"John the Plumber",
         "client":6,
         "custom_fields":[
            
         ],
         "agent_count":0,
         "block_policy_inheritance":false,
         "maintenance_mode":false,
         "failing_checks":{
            "error":false,
            "warning":false
         }
      },
      {
         "id":4,
         "name":"Main",
         "server_policy":null,
         "workstation_policy":null,
         "alert_template":null,
         "client_name":"Plumber",
         "client":3,
         "custom_fields":[
            
         ],
         "agent_count":0,
         "block_policy_inheritance":false,
         "maintenance_mode":false,
         "failing_checks":{
            "error":false,
            "warning":false
         }
      },
      {
         "id":5,
         "name":"Main",
         "server_policy":null,
         "workstation_policy":null,
         "alert_template":null,
         "client_name":"Accountant",
         "client":4,
         "custom_fields":[
            
         ],
         "agent_count":0,
         "block_policy_inheritance":false,
         "maintenance_mode":false,
         "failing_checks":{
            "error":false,
            "warning":false
         }
      },
      {
         "id":6,
         "name":"Main",
         "server_policy":null,
         "workstation_policy":null,
         "alert_template":null,
         "client_name":"Accounting",
         "client":5,
         "custom_fields":[
            
         ],
         "agent_count":0,
         "block_policy_inheritance":false,
         "maintenance_mode":false,
         "failing_checks":{
            "error":false,
            "warning":false
         }
      },
      {
         "id":8,
         "name":"Main",
         "server_policy":null,
         "workstation_policy":null,
         "alert_template":null,
         "client_name":"Mike the Electrician",
         "client":7,
         "custom_fields":[
            
         ],
         "agent_count":0,
         "block_policy_inheritance":false,
         "maintenance_mode":false,
         "failing_checks":{
            "error":false,
            "warning":false
         }
      },
      {
         "id":1,
         "name":"Main",
         "server_policy":null,
         "workstation_policy":null,
         "alert_template":null,
         "client_name":"Clever I.T.",
         "client":1,
         "custom_fields":[
            
         ],
         "agent_count":1,
         "block_policy_inheritance":false,
         "maintenance_mode":false,
         "failing_checks":{
            "error":false,
            "warning":false
         }
      },
      {
         "id":3,
         "name":"Main",
         "server_policy":null,
         "workstation_policy":null,
         "alert_template":null,
         "client_name":"Plumbers",
         "client":2,
         "custom_fields":[
            
         ],
         "agent_count":0,
         "block_policy_inheritance":false,
         "maintenance_mode":false,
         "failing_checks":{
            "error":false,
            "warning":false
         }
      },
      {
         "id":9,
         "name":"US",
         "server_policy":null,
         "workstation_policy":null,
         "alert_template":null,
         "client_name":"Accountant",
         "client":4,
         "custom_fields":[
            
         ],
         "agent_count":0,
         "block_policy_inheritance":false,
         "maintenance_mode":false,
         "failing_checks":{
            "error":false,
            "warning":false
         }
      }
   ]
]

In this example, I want to check “client_name” from the inbound webhook against “client_name” in the GET data and return the value of “client”. Thanks all.

1 Like

Hi @cleveradmin

I would try and merge the 2 by key. Where the first input is from the post and the second is from the get.
Follow that by an IF to see if one of the fields from the GET is filled(if it is not empty the merge succeeded on that record)
If true you got your self a match
If false you don’t

Hope this makes sense and answers the question