IF and multiple items under value2

I’m sure this isn’t difficult, but my searches didn’t find anything. Probably because I’m not searching for the right thing. Hell, you guys know me by now. I know just enough about this stuff to be dangerous! I’m writing a workflow that takes a string and splits up the words into variables, resulting in var1, var2, var3, etc. Although I don’t expect the string to be longer than 5 or 6 words, I can’t say for sure. I want to take those variables and check if they match against a list of predefined words. So basically using the IF node and contains, but value1 needs to cycle through the variables and value2 needs to be any of the list of words. Then, the workflow will move to an HTTP request if a match is found. Right now, I’m only interested in the first match. But eventually, I’d like it to cycle through each match and run the HTTP request for each match. I’m going to elaborate below on what I’m looking to do short-term and long-term.

Short-term
I’m pulling data from a webhook notification that will have a ticket subject line. Let’s pretend this subject line is “Quickbooks and my email are not working”. My current workflow would take that string and split it into words, so var1=“Quickbooks”, var2=“and”, var3=“my”, var4=“email”, var5=“are”, var6=“not”, var7=“working”. Then I want to see if any of these variables match my list of words. Let’s pretend those words are “QuickBooks”, “email”, “outlook”, “DNS”. For now, the first match will then be used to run an HTTP request to a Bookstack API, which is already in place, to find any pages with a tag with the matching word. In this example, that tag would be QuickBooks and we would then query https://domain.tld/api/search?query={type:page}+[quickbooks]&page=1&count=5. This would give us up to 5 pages that have the QuickBooks tag. We are then going to update the ticket with a private note with links to those pages (not done yet, but this will be easy) for the technician who is assigned the ticket to easily reference.

Long-term
Ultimately, I’d love to have this cycle through each variable and for each match, pull the pages from Bookstack and then combine all the resulting URLs into one list and update the ticket. Unfortunately, the Bookstack API only allows for searching for pages that match multiple tags (AND vs OR). So each match would require a separate API search. In the example above, there would be a match for both “QuickBooks” and “email”. I’m thinking once I have my “short-term” workflow done, I’ll post it here and work through the long-term requirements.

Oh wow, this sounds like a tricky one but let’s break this down. The part you have described under short-term is already working (with the exception of the private not part saying not done yet)?

To make sure I understand your question right, you’ll have two different sources of n8n items: one with the items from the split-up string and one with a bunch of words you’d like to find amongst the first one. This could be done like so:

Example Workflow
{
  "nodes": [
    {
      "parameters": {
        "mode": "keepKeyMatches",
        "propertyName1": "value",
        "propertyName2": "tag"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    value: \"foo\"\n  }\n}, {\n  json: {\n    value: \"bar\"\n  }\n}, {\n  json: {\n    value: \"baz\"\n  }\n}, {\n  json: {\n    value: \"qux\"\n  }\n}]"
      },
      "name": "Set Example Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    tag: \"baz\"\n  }\n}, {\n  json: {\n    tag: \"qux\"\n  }\n}]"
      },
      "name": "Set Match List",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        400
      ]
    },
    {
      "parameters": {
        "mode": "keepKeyMatches",
        "propertyName1": "value",
        "propertyName2": "tag"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Example Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Set Match List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Example Data": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Match List": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}

This example uses the Merge node which can also act as a filter. In its Keep Key Matches mode, it only let’s items from our first list pass if there is a match in the second list.

If you put an HTTP Request node behind this Merge node, it would run once for each item the Merge node outputs:

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    value: \"foo\"\n  }\n}, {\n  json: {\n    value: \"bar\"\n  }\n}, {\n  json: {\n    value: \"baz\"\n  }\n}, {\n  json: {\n    value: \"qux\"\n  }\n}]"
      },
      "name": "Set Example Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    tag: \"baz\"\n  }\n}, {\n  json: {\n    tag: \"qux\"\n  }\n}]"
      },
      "name": "Set Match List",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        400
      ]
    },
    {
      "parameters": {
        "mode": "keepKeyMatches",
        "propertyName1": "value",
        "propertyName2": "tag"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://domain.tld/api/search",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "page",
              "value": "1"
            },
            {
              "name": "count",
              "value": "5"
            },
            {
              "name": "query",
              "value": "={type:page}+[{{$json[\"value\"]}}]"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Example Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Set Match List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Example Data": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Match List": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Is this what you had in mind?

Yes! Ok, this is working exactly as I expected and using two matched keywords I’ve got to successfully query and pull down four results from Bookstack. Now, what I need to do is figure out how to take those results and merge them into a single string that I can then push into our ticketing system using their API. I’m basically looking to isolate out the name and the id from the json below so that I’d end up with something like this: “Basic Quickbooks server troubleshooting (https://domain.tld/link/12), Add new user (https://domain.tld/link/29), Quickbooks database server not running (https://domain.tld/link/59), Enable Email Forwarding (https://domain.tld/link/35).”

[
   {
      "data":[
         {
            "name":"Basic Quickbooks server troubleshooting",
            "id":12,
            "slug":"basic-quickbooks-server-troubleshooting",
            "book_id":9,
            "chapter_id":9,
            "draft":false,
            "template":false,
            "created_at":"2021-11-19T16:38:54.000000Z",
            "updated_at":"2021-11-19T16:52:22.000000Z",
            "type":"page",
            "tags":[
               {
                  "name":"quickbooks",
                  "value":"",
                  "order":0
               },
               {
                  "name":"server",
                  "value":"",
                  "order":0
               }
            ]
         },
         {
            "name":"Add new user",
            "id":29,
            "slug":"add-new-user",
            "book_id":9,
            "chapter_id":9,
            "draft":false,
            "template":false,
            "created_at":"2021-11-24T01:28:04.000000Z",
            "updated_at":"2021-11-24T01:39:39.000000Z",
            "type":"page",
            "tags":[
               {
                  "name":"quickbooks",
                  "value":"",
                  "order":0
               }
            ]
         },
         {
            "name":"Quickbooks database server not running",
            "id":59,
            "slug":"quickbooks-database-server-not-running",
            "book_id":9,
            "chapter_id":9,
            "draft":false,
            "template":false,
            "created_at":"2021-11-28T15:02:51.000000Z",
            "updated_at":"2021-11-28T15:09:00.000000Z",
            "type":"page",
            "tags":[
               {
                  "name":"quickbooks",
                  "value":"",
                  "order":0
               },
               {
                  "name":"dns",
                  "value":"",
                  "order":0
               }
            ]
         }
      ],
      "total":3
   },
   {
      "data":[
         {
            "name":"Enable Email Forwarding",
            "id":35,
            "slug":"enable-email-forwarding",
            "book_id":10,
            "chapter_id":11,
            "draft":false,
            "template":false,
            "created_at":"2021-11-25T13:53:47.000000Z",
            "updated_at":"2021-11-25T14:03:34.000000Z",
            "type":"page",
            "tags":[
               {
                  "name":"microsoft365",
                  "value":"",
                  "order":0
               },
               {
                  "name":"microsoft",
                  "value":"",
                  "order":0
               },
               {
                  "name":"exchange",
                  "value":"",
                  "order":0
               },
               {
                  "name":"email",
                  "value":"",
                  "order":0
               },
               {
                  "name":"forwarding",
                  "value":"",
                  "order":0
               }
            ]
         }
      ],
      "total":1
   }
]