Search JSON Results for ID

Brand new to n8n, but have successfully created a few simple workflows. This one is slightly more complex, but I’m sure it will be easy for someone here. My workflow is getting JSON data from a GET HTTP request, which generates the results below (cleaned up for public consumption). What I need is to separate out the JSON record under “contacts” that has a “phone” or “mobile” that matches the number I’m getting via a webhook earlier in my workflow. I am then going to take the “id” from that contact and use it in a HTTP request later in my workflow.

[
    {
        "customers": [
            {
                "id": 123456789,
                "firstname": "n8n",
                "lastname": "Developer",
                "fullname": "n8n Developer",
                "business_name": "n8n Inc.",
                "contacts": [
                    {
                        "id": 987654321,
                        "name": "Not The Guy",
                        "address1": "",
                        "address2": "",
                        "city": "",
                        "state": "",
                        "zip": "",
                        "email": "",
                        "phone": "",
                        "mobile": "",
                        "latitude": null,
                        "longitude": null,
                        "customer_id": 123456789
                    },
                    {
                        "id": 8675309,
                        "name": "Definitely the Guy",
                        "address1": "",
                        "address2": "",
                        "city": "",
                        "state": "",
                        "zip": "",
                        "email": "",
                        "phone": "+15551111234",
                        "mobile": "",
                        "latitude": null,
                        "longitude": null,
                        "customer_id": 123456789
                    }
                ]
            }
        ],
        "meta": {
            "total_pages": 1,
            "total_entries": 1,
            "per_page": 100,
            "page": 1
        }
    }
]

@cleveradmin welcome to the community.

Check the example below:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        40,
        280
      ]
    },
    {
      "parameters": {
        "url": "https://testing-endpoint-up3kz1qu6c5y.runkit.sh/",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        300,
        100
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "phonenumber",
              "value": "+15551111234"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        300,
        280
      ],
      "notesInFlow": true,
      "notes": "Webhook mockup"
    },
    {
      "parameters": {
        "mode": "passThrough",
        "output": "input2"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        550,
        210
      ]
    },
    {
      "parameters": {
        "functionCode": "\nconst results = [];\n\nconst customers = $item(\"0\").$node[\"HTTP Request\"].json[\"customers\"];\n\nconst phone = items[0].json.phonenumber\n\nfor (const customer of customers) {\n  for (const contact of customer.contacts) {\n    if (contact.phone === phone || contact.mobile === phone) {\n      results.push({ json: { contactId: contact.id } })\n    }\n  }\n}\n\nreturn results;\n\n\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        760,
        210
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I kind of see where you are going with this, but putting it into my existing workflow doesn’t work and I’m not sure exactly why. It will probably help to walk through my workflow.

  1. Inbound webhook: posted to by phone system providing caller ID of caller formatted as “+12223331234”.
  2. Set to grab the number from the webhook.
  3. Second set to reformat the number to remove the + from the start (I’m sure I don’t need two sets for this, but for some reason, that’s how I have it).
  4. HTTP request to grab the json containing the customer and contact information.
  5. And now your function to return the contact ID matching the phone number from the inbound webhook. Now, this part needs to match against the reformatted number from my second set because the + doesn’t exist in the customer information.

So the second set does result in the following JSON, but the function doesn’t return any data.

[
   {
      "phonenumber":"15551111234"
   }
]

Hey @cleveradmin!

To combine 2 and 3 you can use the .replace() method in the Expression Editor. Check the below example:

You can use the IF node to check if the values match and design your workflow accordingly. You can even use the Merge node to merge the values. In the Merge node, you can use the Merge By Key operation.

Thanks, I’ll play around with that. I’m not sure if the IF node will work here because I don’t think IF can search JSON results. What @RicardoE105 provided seems to be the right idea, it’s just not working in my workflow and I’m not sure why. I think what I’ll do next is to rewrite my workflow to use the fake data I’ve already provided so that I can be more transparent here.

You can also do:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://testing-endpoint-up3kz1qu6c5y.runkit.sh/",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        700,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "phonenumber",
              "value": "+15551111234"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        470,
        300
      ],
      "notesInFlow": true,
      "notes": "Webhook mockup"
    },
    {
      "parameters": {
        "functionCode": "const results = [];\n\nconst customers = items[0].json.customers\n\nfor (const { contacts } of customers) {\n  for (const contact of contacts) {\n    results.push({ json: contact })\n  }\n}\n\nreturn results;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        910,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Function1\"].json[\"phone\"]}}",
              "value2": "={{$item(0).$node[\"Set\"].json[\"phonenumber\"]}}"
            },
            {
              "value1": "={{$node[\"Function1\"].json[\"mobile\"]}}",
              "value2": "={{$item(0).$node[\"Set\"].json[\"phonenumber\"]}}"
            }
          ]
        },
        "combineOperation": "any"
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1100,
        300
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1330,
        450
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        null,
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }

}

@RicardoE105 After integrating it into my workflow, this only seems to work if the first contact matches. When I swapped it around so that “Not the Guy” had the correct phone number, it works. I’m not sure why. I’ve modified my workflow to not use anything “real”, but still give me the same results I’m working off. Hopefully this makes sense. Phone to PSA - cc0e1ab9

Ok I dug into this more and took another run at it. No matter what I do here, using my original data (cleaned up for public consumption), it will always give me the first “contact” even though there is no match. This also works a bit differently in that I’m cleaning up the numbers to remove anything that isn’t a number during the match. I have to stop looking at this now or I’m going to lose my mind. Any help would be appreciated.

Try it like this:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        230,
        310
      ]
    },
    {
      "parameters": {
        "url": "https://5ea797ea052c31e95a2806ff7e3c62d5.m.pipedream.net",
        "options": {}
      },
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        490,
        310
      ]
    },
    {
      "parameters": {
        "functionCode": "const results = [];\n\nconst customers = items[0].json.customers\n\nfor (const { contacts } of customers) {\n  for (const contact of contacts) {\n    results.push({ json: contact })\n  }\n}\n\nreturn results;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        990,
        310
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Function1\"].json[\"phone\"].match(/\\d+/g)[0]}}",
              "value2": "={{$item(0).$node[\"HTTP Request2\"].json[\"body\"][\"external_number\"].match(/\\d+/g)[0]}}"
            },
            {
              "value1": "={{$node[\"Function1\"].json[\"mobile\"].match(/\\d+/g)[0]}}",
              "value2": "={{$item(0).$node[\"HTTP Request2\"].json[\"body\"][\"external_number\"].match(/\\d+/g)[0]}}"
            }
          ]
        },
        "combineOperation": "any"
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1220,
        310
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1450,
        290
      ]
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "url": "=https://ec174e5f24f859a946d4de9f46ea831b.m.pipedream.net",
        "options": {}
      },
      "name": "GetCustomer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        760,
        310
      ],
      "credentials": {
        "httpHeaderAuth": "asasasasas"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "GetCustomer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetCustomer": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@RicardoE105 Yes that seems to work! What changed specifically?

I changed {{$node["HTTP Request2"].json["body"]["external_number"].match(/\d+/g)[0]}} for {{$item(0).$node["HTTP Request2"].json["body"]["external_number"].match(/\d+/g)[0]}}.

The problem is that in the IF node, you are referencing data from nodes that have 2 different output lengths. The HTTP Request2 returns just one item, and the function1 returns more than one item.

In the first iteration it will work because both outputs have index 0, but after that, the expression {{$node["HTTP Request2"].json["body"]["external_number"].match(/\d+/g)[0]}} is going to return undefined because it does not have data for an index > 0. By adding the $item(0), we tell the expression to always use the the index 0 no matter the iteration index.

I hope that makes sense.

Yes, it does thank you. And I have now progressed in my workflow to my next problem. Later in the workflow I’m using an HTTP request to find any open tickets belonging to the contact who is calling us. I want to use an IF to basically update an existing ticket via another HTTP request or create a new ticket if there isn’t an existing ticket. Here is the result if a ticket exists:

[
   {
      "tickets":[
         {
            "id":123456789,
            "number":7662,
            "subject":"Support Test",
            "created_at":"2021-04-01T22:36:14.985-06:00",
            "customer_id":987654321,
            "customer_business_then_name":"Not So Clever Admin",
            "due_date":"2021-04-04T22:36:14.978-06:00",
            "resolved_at":null,
            "start_at":null,
            "end_at":null,
            "location_id":null,
            "problem_type":"Other",
            "status":"New",
            "ticket_type_id":null,
            "properties":{
               
            },
            "user_id":null,
            "updated_at":"2021-04-01T22:36:15.547-06:00",
            "pdf_url":null,
            "priority":"2 Normal",
            "comments":[
               {
                  "id":1111111,
                  "created_at":"2021-04-01T22:36:14.929-06:00",
                  "updated_at":"2021-04-01T22:36:15.525-06:00",
                  "ticket_id":123456789,
                  "subject":"Initial Issue",
                  "body":"This is a test",
                  "tech":"",
                  "hidden":false,
                  "user_id":11111
               }
            ],
            "user":null
         }
      ],
      "meta":{
         "total_pages":1,
         "page":1
      }
   }
]

And this is what’s returned if there are no tickets:

[
   {
      "tickets":[
         
      ],
      "meta":{
         "total_pages":1,
         "page":1
      }
   }
]

How can I use IF to return True if there is a ticket and False if there is not? Thanks so much for your help!

ahh yes, you can do that. Check the example below:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: \n   {\n      \"tickets\":[\n         {\n            \"id\":123456789,\n            \"number\":7662,\n            \"subject\":\"Support Test\",\n            \"created_at\":\"2021-04-01T22:36:14.985-06:00\",\n            \"customer_id\":987654321,\n            \"customer_business_then_name\":\"Not So Clever Admin\",\n            \"due_date\":\"2021-04-04T22:36:14.978-06:00\",\n            \"resolved_at\":null,\n            \"start_at\":null,\n            \"end_at\":null,\n            \"location_id\":null,\n            \"problem_type\":\"Other\",\n            \"status\":\"New\",\n            \"ticket_type_id\":null,\n            \"properties\":{\n               \n            },\n            \"user_id\":null,\n            \"updated_at\":\"2021-04-01T22:36:15.547-06:00\",\n            \"pdf_url\":null,\n            \"priority\":\"2 Normal\",\n            \"comments\":[\n               {\n                  \"id\":1111111,\n                  \"created_at\":\"2021-04-01T22:36:14.929-06:00\",\n                  \"updated_at\":\"2021-04-01T22:36:15.525-06:00\",\n                  \"ticket_id\":123456789,\n                  \"subject\":\"Initial Issue\",\n                  \"body\":\"This is a test\",\n                  \"tech\":\"\",\n                  \"hidden\":false,\n                  \"user_id\":11111\n               }\n            ],\n            \"user\":null\n         }\n      ],\n      \"meta\":{\n         \"total_pages\":1,\n         \"page\":1\n      }\n   }\n  },\n  {\n    json: {\n      tickets: [\n      ]\n    }\n  }\n] "
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        490,
        300
      ],
      "notesInFlow": true,
      "notes": "HTTP Mockup Request"
    },
    {
      "parameters": {
        "conditions": {
          "number": [],
          "boolean": [
            {
              "value1": "={{(!$node[\"Function\"].json[\"tickets\"].length) ? false : true}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        750,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Awesome, that works great! Thanks so much for your help @RicardoE105!

1 Like

Ran into one other issue. In the IF that is checking the incoming phone number against the customer contacts, TRUE is the matching contact and FALSE is all the other contacts. My plan is to have FALSE trigger a different set of actions to create a new ticket against the customer without a contact. But I only want that to happen if there is no contact match. In the current form, it proceeds to both TRUE and FALSE, resulting in a ticket being created for the customer with a contact AND a ticket being created for the customer without a contact. I’m not sure how to change that. Cheers.

So I suspect that this actually makes sense as I’ve just realized that if I have another step in the workflow for FALSE, I’m forcing it to complete that next step even if there is no value for false. So I’m assuming there is a way for me to have it only proceed under the right conditions; maybe another IF? Thanks again.

Can you share your current workflow so that I can have a better look?

My plan is to have FALSE trigger a different set of actions to create a new ticket against the customer without a contact. But I only want that to happen if there is no contact match

In my mind, this is what the current workflow should be doing. Maybe I’m missing something.

@RicardoE105 I just took your workflow from earlier in this thread and added a Set connected to the false off the IF. What happens here is exactly what I’m seeing in my workflow.

Ok, I think I know understand what you want to do. Check the example below:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        180,
        290
      ]
    },
    {
      "parameters": {
        "url": "https://5ea797ea052c31e95a2806ff7e3c62d5.m.pipedream.net",
        "options": {}
      },
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        480,
        290
      ]
    },
    {
      "parameters": {
        "functionCode": "const results = [];\n\nconst customers = items[0].json.customers\n\nfor (const { contacts } of customers) {\n  for (const contact of contacts) {\n    results.push({ json: contact })\n  }\n}\n\nreturn results;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        940,
        290
      ],
      "notesInFlow": true,
      "notes": "Get all contacts"
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Function1\"].json[\"phone\"].match(/\\d+/g)[0]}}",
              "value2": "={{$item(0).$node[\"HTTP Request2\"].json[\"body\"][\"external_number\"].match(/\\d+/g)[0]}}"
            },
            {
              "value1": "={{$node[\"Function1\"].json[\"mobile\"].match(/\\d+/g)[0]}}",
              "value2": "={{$item(0).$node[\"HTTP Request2\"].json[\"body\"][\"external_number\"].match(/\\d+/g)[0]}}"
            }
          ]
        },
        "combineOperation": "any"
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1170,
        290
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1450,
        420
      ]
    },
    {
      "parameters": {
        "functionCode": "const results = [];\n\nconst customers = items[0].json.customers\n\nfor (const customer of customers) {\n    console.log(customer)\n    if (customer.contacts.length === 0) {\n        results.push({ json: customer })\n    }\n}\n\nreturn results;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1040,
        570
      ],
      "notesInFlow": true,
      "notes": "Get customers without a contact"
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      customers: [\n  {\n    \"id\": 123456789,\n    \"firstname\": \"M\",\n    \"lastname\": \"C\",\n    \"fullname\": \"MC\",\n    \"business_name\": \"Not So Clever Admin\",\n    \"email\": \"[email protected]\",\n    \"phone\": \"12345556922\",\n    \"mobile\": \"12345556922\",\n    \"created_at\": \"2018-07-19T21:04:30.161-06:00\",\n    \"updated_at\": \"2020-09-09T20:49:26.594-06:00\",\n    \"pdf_url\": null,\n    \"address\": null,\n    \"address_2\": null,\n    \"city\": null,\n    \"state\": null,\n    \"zip\": null,\n    \"latitude\": null,\n    \"longitude\": null,\n    \"notes\": null,\n    \"get_sms\": true,\n    \"opt_out\": false,\n    \"disabled\": false,\n    \"no_email\": false,\n    \"location_name\": null,\n    \"location_id\": null,\n    \"properties\": {\n      \"Jumpcloud\": \"\",\n      \"Splashtop\": \"\",\n      \"ATTENTION: \": \"\",\n      \"AutoElevate\": \"0\",\n      \"Cylance Name\": \"\",\n      \"Invoice Name\": \"\",\n      \"Acronis Token\": \"\",\n      \"DNSFilter Key\": \"\",\n      \"Huntress Name\": \"\",\n      \"Remote Access\": \"0\",\n      \"Comet Backup PW\": \"\",\n      \"Comet Backup UN\": \"\",\n      \"Solarwinds Backup\": \"\",\n      \"ITSP Activation Code\": \"\",\n      \"Local Admin Password\": \"\",\n      \"notification_billing\": \"1\",\n      \"notification_reports\": \"1\",\n      \"Cloud Backup Password\": \"\",\n      \"Cloud Backup Username\": \"\",\n      \"TIMESHEET APPROVED BY:\": \"\",\n      \"notification_marketing\": \"1\"\n    },\n    \"online_profile_url\": \"\",\n    \"tax_rate_id\": null,\n    \"notification_email\": \"\",\n    \"invoice_cc_emails\": \"\",\n    \"invoice_term_id\": null,\n    \"referred_by\": null,\n    \"ref_customer_id\": null,\n    \"business_and_full_name\": \"Not So Clever Admin - M C\",\n    \"business_then_name\": \"Not So Clever Admin\",\n    \"contacts\": [\n      {\n        \"id\": 111111,\n        \"name\": \"Ben\",\n        \"address1\": \"\",\n        \"address2\": \"\",\n        \"city\": \"\",\n        \"state\": \"\",\n        \"zip\": \"\",\n        \"email\": \"[email protected]\",\n        \"phone\": \"\",\n        \"mobile\": \"\",\n        \"latitude\": null,\n        \"longitude\": null,\n        \"customer_id\": 123456789,\n        \"account_id\": 666,\n        \"notes\": \"\",\n        \"created_at\": \"2020-01-26T10:47:58.467-07:00\",\n        \"updated_at\": \"2020-01-26T10:48:07.234-07:00\",\n        \"vendor_id\": null,\n        \"properties\": {},\n        \"opt_out\": false,\n        \"extension\": \"\",\n        \"processed_phone\": \"\",\n        \"processed_mobile\": \"\",\n        \"ticket_matching_emails\": null\n      },\n      {\n        \"id\": 222222,\n        \"name\": \"M C\",\n        \"address1\": \"\",\n        \"address2\": null,\n        \"city\": \"\",\n        \"state\": \"\",\n        \"zip\": \"\",\n        \"email\": \"[email protected]\",\n        \"phone\": \"+12345556666\",\n        \"mobile\": \"+12345556667\",\n        \"latitude\": null,\n        \"longitude\": null,\n        \"customer_id\": 123456789,\n        \"account_id\": 666,\n        \"notes\": null,\n        \"created_at\": \"2020-05-14T13:25:40.835-06:00\",\n        \"updated_at\": \"2020-05-14T13:25:40.835-06:00\",\n        \"vendor_id\": null,\n        \"properties\": {},\n        \"opt_out\": false,\n        \"extension\": null,\n        \"processed_phone\": \"14031111234\",\n        \"processed_mobile\": \"14032221234\",\n        \"ticket_matching_emails\": null\n      },\n      {\n        \"id\": 333333,\n        \"name\": \"M C\",\n        \"address1\": \"\",\n        \"address2\": null,\n        \"city\": \"\",\n        \"state\": \"\",\n        \"zip\": \"\",\n        \"email\": \"[email protected]\",\n        \"phone\": \"+14431111234\",\n        \"mobile\": null,\n        \"latitude\": null,\n        \"longitude\": null,\n        \"customer_id\": 123456789,\n        \"account_id\": 666,\n        \"notes\": null,\n        \"created_at\": \"2020-01-27T17:02:12.005-07:00\",\n        \"updated_at\": \"2020-01-30T22:04:58.166-07:00\",\n        \"vendor_id\": null,\n        \"properties\": {},\n        \"opt_out\": false,\n        \"extension\": null,\n        \"processed_phone\": \"\",\n        \"processed_mobile\": null,\n        \"ticket_matching_emails\": null\n      },\n      {\n        \"id\": 444444,\n        \"name\": \"M T\",\n        \"address1\": \"\",\n        \"address2\": null,\n        \"city\": \"\",\n        \"state\": \"\",\n        \"zip\": \"\",\n        \"email\": \"[email protected]\",\n        \"phone\": \"+1 (555) 666-7777\",\n        \"mobile\": \"15557776666\",\n        \"latitude\": null,\n        \"longitude\": null,\n        \"customer_id\": 123456789,\n        \"account_id\": 666,\n        \"notes\": null,\n        \"created_at\": \"2020-05-14T13:25:11.213-06:00\",\n        \"updated_at\": \"2020-05-14T13:25:11.213-06:00\",\n        \"vendor_id\": null,\n        \"properties\": {},\n        \"opt_out\": false,\n        \"extension\": null,\n        \"processed_phone\": \"\",\n        \"processed_mobile\": \"\",\n        \"ticket_matching_emails\": null\n      },\n      {\n        \"id\": 555555,\n        \"name\": \"T I\",\n        \"address1\": null,\n        \"address2\": null,\n        \"city\": null,\n        \"state\": null,\n        \"zip\": null,\n        \"email\": \"[email protected]\",\n        \"phone\": \"+14567890200\",\n        \"mobile\": \"+14567782663\",\n        \"latitude\": null,\n        \"longitude\": null,\n        \"customer_id\": 123456789,\n        \"account_id\": 666,\n        \"notes\": null,\n        \"created_at\": \"2020-05-14T13:25:49.367-06:00\",\n        \"updated_at\": \"2020-05-14T13:25:49.367-06:00\",\n        \"vendor_id\": null,\n        \"properties\": {},\n        \"opt_out\": false,\n        \"extension\": null,\n        \"processed_phone\": \"\",\n        \"processed_mobile\": \"\",\n        \"ticket_matching_emails\": null\n      }\n    ]\n  },\n  {\n    \"id\": 12345678909,\n    \"firstname\": \"M\",\n    \"lastname\": \"C\",\n    \"fullname\": \"MC\",\n    \"business_name\": \"Not So Clever Admin\",\n    \"email\": \"[email protected]\",\n    \"phone\": \"12312345556922\",\n    \"mobile\": \"123121345556922\",\n    \"created_at\": \"2018-07-19T21:04:30.161-06:00\",\n    \"updated_at\": \"2020-09-09T20:49:26.594-06:00\",\n    \"pdf_url\": null,\n    \"address\": null,\n    \"address_2\": null,\n    \"city\": null,\n    \"state\": null,\n    \"zip\": null,\n    \"latitude\": null,\n    \"longitude\": null,\n    \"notes\": null,\n    \"get_sms\": true,\n    \"opt_out\": false,\n    \"disabled\": false,\n    \"no_email\": false,\n    \"location_name\": null,\n    \"location_id\": null,\n    \"properties\": {\n      \"Jumpcloud\": \"\",\n      \"Splashtop\": \"\",\n      \"ATTENTION: \": \"\",\n      \"AutoElevate\": \"0\",\n      \"Cylance Name\": \"\",\n      \"Invoice Name\": \"\",\n      \"Acronis Token\": \"\",\n      \"DNSFilter Key\": \"\",\n      \"Huntress Name\": \"\",\n      \"Remote Access\": \"0\",\n      \"Comet Backup PW\": \"\",\n      \"Comet Backup UN\": \"\",\n      \"Solarwinds Backup\": \"\",\n      \"ITSP Activation Code\": \"\",\n      \"Local Admin Password\": \"\",\n      \"notification_billing\": \"1\",\n      \"notification_reports\": \"1\",\n      \"Cloud Backup Password\": \"\",\n      \"Cloud Backup Username\": \"\",\n      \"TIMESHEET APPROVED BY:\": \"\",\n      \"notification_marketing\": \"1\"\n    },\n    \"online_profile_url\": \"\",\n    \"tax_rate_id\": null,\n    \"notification_email\": \"\",\n    \"invoice_cc_emails\": \"\",\n    \"invoice_term_id\": null,\n    \"referred_by\": null,\n    \"ref_customer_id\": null,\n    \"business_and_full_name\": \"Not So Clever Admin - M C\",\n    \"business_then_name\": \"Not So Clever Admin\",\n    \"contacts\": [\n      \n    ]\n  }\n]\n  },\n  }\n]"
      },
      "name": "Function2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        690,
        290
      ],
      "notesInFlow": true,
      "notes": "Mockup get customers"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "Function2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        null,
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function2": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Yes, that did work. But we’ve had to start over and rewrite the workflow as the API we initially used won’t actually work the way we need it to. So now we need to query a different API to give us a list of contacts and then match that contact against our inbound number. I am struggling to figure out how to format the IF statement I need in order to find a match here. Can you provide some direction?

Here is the query JSON:

[
   {
      "contacts":[
         {
            "id":111111,
            "name":"Wrong Guy",
            "address1":"",
            "address2":"",
            "city":"",
            "state":"",
            "zip":"",
            "email":"",
            "phone":"5554441111",
            "mobile":"",
            "latitude":null,
            "longitude":null,
            "customer_id":666666,
            "account_id":123456,
            "notes":"",
            "created_at":"2021-04-05T12:46:59.736-06:00",
            "updated_at":"2021-04-05T12:47:16.196-06:00",
            "vendor_id":null,
            "properties":{
               "title":""
            },
            "opt_out":false,
            "extension":"",
            "processed_phone":"5554441111",
            "processed_mobile":"",
            "ticket_matching_emails":""
         },
         {
            "id":222222,
            "name":"Right Guy",
            "address1":"",
            "address2":"",
            "city":"",
            "state":"",
            "zip":"",
            "email":"",
            "phone":"5554442222",
            "mobile":"",
            "latitude":null,
            "longitude":null,
            "customer_id":666666,
            "account_id":54321,
            "notes":"",
            "created_at":"2021-04-05T11:19:04.172-06:00",
            "updated_at":"2021-04-05T11:19:22.085-06:00",
            "vendor_id":null,
            "properties":{
               "title":""
            },
            "opt_out":false,
            "extension":"",
            "processed_phone":"5554442222",
            "processed_mobile":"",
            "ticket_matching_emails":""
         }
      ],
      "meta":{
         "total_pages":1,
         "total_entries":2,
         "per_page":50,
         "page":1
      }
   }
]

We want to match our external number, which in this example is 5554442222 and return all the details for that contact to use later in our workflow. If there is no match, we proceed to a different path in our workflow to then try and search for a customer with that phone number (which we already have from our previous work with you). Thank you!