Set Based on Clockify Data Match

I’m receiving JSON via a Webhook from Clockify that looks like this.

[
   {
      "headers":{
         "connection":"Keep-Alive"
      },
      "params":{
         
      },
      "query":{
         
      },
      "body":{
         "id":"112233445566",
         "description":"Now I explain some that other thing again.",
         "userId":"12345678",
         "billable":true,
         "projectId":"98765432",
         "timeInterval":{
            "start":"2021-04-07T15:00:52Z",
            "end":"2021-04-07T15:01:37Z",
            "duration":"PT45S"
         },
         "workspaceId":"1232567898",
         "isLocked":false,
         "hourlyRate":null,
         "costRate":null,
         "customFieldValues":[
            
         ],
         "project":{
            "name":"Ticket 4209 - Not so Clever Admin [4066632296]",
            "clientId":"",
            "workspaceId":"1232567898",
            "billable":true,
            "estimate":{
               "estimate":"PT0S",
               "type":"AUTO"
            },
            "color":"#00BCD4",
            "archived":false,
            "clientName":"",
            "duration":"PT0S",
            "note":"",
            "activeEstimate":"NONE",
            "timeEstimate":{
               "estimate":0,
               "type":"AUTO",
               "resetOption":null
            },
            "budgetEstimate":null,
            "id":"5658785125",
            "public":true,
            "template":false
         },
         "task":null,
         "user":{
            "id":"12345678",
            "name":"Clever Technician",
            "status":"ACTIVE"
         },
         "tags":[
            
         ]
      }
   }
]

Separately, I have a Set with two values in it:

Name: Clever Technician
Value: 56234

Name: Stupid Technician
Value: 62134

What I want to do is compare [“user”][“name”] from the Webhook against the two values in my Set and return the value from the match. Then I’m going to use that value later in my workflow to update my PSA with the information from Clockify. Thank you!

Hey @cleveradmin!

Here’s a solution that can be helpful

{
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{Object.keys($json)[0]}}",
              "value2": "={{$node[\"Webhook\"].json[\"body\"][\"user\"][\"name\"]}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Clever Technician",
              "value": "1234"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "path": "82faf9c3-d813-4c74-95a0-97649c63d4b2",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "webhookId": "82faf9c3-d813-4c74-95a0-97649c63d4b2"
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I am getting the user name set in the Set node using a JavaScript code snippet. The example above shows for only one condition, but you can add another condition and set the Combine option to Any.

Hope this helps :slight_smile:

Sorry @harshil1712, but I’m not entirely clear on how this helps me. I took your example and connected it to a fake Webhook and modified the Set with the two values I’m working with. All that seems to happen here is that it matches the technician name and then outputs both values. Essentially, I need it to check which technician name matches against the Webhook data and then output the numerical ID for the match.

{
  "name": "test",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{Object.keys($json)[0]}}",
              "value2": "={{$node[\"HTTP Request\"].json[\"0\"][\"body\"][\"user\"][\"name\"]}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1080,
        400
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Clever Technician",
              "value": "1234"
            },
            {
              "name": "Stupid Technician",
              "value": "4567"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        900,
        400
      ]
    },
    {
      "parameters": {
        "url": "https://92ce0939ad9c105b73e8271b9474834e.m.pipedream.net",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        700,
        400
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        []
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": "10"
}

@cleveradmin Check the example below:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: \n   {\n      \"headers\":{\n         \"connection\":\"Keep-Alive\"\n      },\n      \"params\":{\n         \n      },\n      \"query\":{\n         \n      },\n      \"body\":{\n         \"id\":\"112233445566\",\n         \"description\":\"Now I explain some that other thing again.\",\n         \"userId\":\"12345678\",\n         \"billable\":true,\n         \"projectId\":\"98765432\",\n         \"timeInterval\":{\n            \"start\":\"2021-04-07T15:00:52Z\",\n            \"end\":\"2021-04-07T15:01:37Z\",\n            \"duration\":\"PT45S\"\n         },\n         \"workspaceId\":\"1232567898\",\n         \"isLocked\":false,\n         \"hourlyRate\":null,\n         \"costRate\":null,\n         \"customFieldValues\":[\n            \n         ],\n         \"project\":{\n            \"name\":\"Ticket 4209 - Not so Clever Admin [4066632296]\",\n            \"clientId\":\"\",\n            \"workspaceId\":\"1232567898\",\n            \"billable\":true,\n            \"estimate\":{\n               \"estimate\":\"PT0S\",\n               \"type\":\"AUTO\"\n            },\n            \"color\":\"#00BCD4\",\n            \"archived\":false,\n            \"clientName\":\"\",\n            \"duration\":\"PT0S\",\n            \"note\":\"\",\n            \"activeEstimate\":\"NONE\",\n            \"timeEstimate\":{\n               \"estimate\":0,\n               \"type\":\"AUTO\",\n               \"resetOption\":null\n            },\n            \"budgetEstimate\":null,\n            \"id\":\"5658785125\",\n            \"public\":true,\n            \"template\":false\n         },\n         \"task\":null,\n         \"user\":{\n            \"id\":\"12345678\",\n            \"name\":\"Clever Technician\",\n            \"status\":\"ACTIVE\"\n         },\n         \"tags\":[\n            \n         ]\n      }\n   }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        480,
        300
      ],
      "notesInFlow": true,
      "notes": "Mockup webhook"
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Clever Technician",
              "value": "56234"
            },
            {
              "name": "Stupid Technician",
              "value": "62134"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        730,
        290
      ]
    },
    {
      "parameters": {
        "functionCode": "\nconst results = [];\n\nconst user = $node[\"Function\"].json[\"body\"][\"user\"];\n\nconst persons = items[0].json\n\nfor (key of Object.keys(persons)) {\n  if (key === user.name) {\n    results.push({ json: { id: user.id, name: key } })\n  }\n}\n\nreturn results;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        980,
        290
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks @RicardoE105, but this returns the wrong data. It’s returning the user.id from the webhook, but I actually need it to return the number associated with the Set. So if “Clever Technician” from the set matches user.name from the Webhook, it should return 56234 from the Set. Maybe there’s a cleaner way to do this?

@cleveradmin

   {
      "nodes": [
        {
          "parameters": {},
          "name": "Start",
          "type": "n8n-nodes-base.start",
          "typeVersion": 1,
          "position": [
            250,
            300
          ]
        },
        {
          "parameters": {
            "functionCode": "return [\n  {\n    json: \n   {\n      \"headers\":{\n         \"connection\":\"Keep-Alive\"\n      },\n      \"params\":{\n         \n      },\n      \"query\":{\n         \n      },\n      \"body\":{\n         \"id\":\"112233445566\",\n         \"description\":\"Now I explain some that other thing again.\",\n         \"userId\":\"12345678\",\n         \"billable\":true,\n         \"projectId\":\"98765432\",\n         \"timeInterval\":{\n            \"start\":\"2021-04-07T15:00:52Z\",\n            \"end\":\"2021-04-07T15:01:37Z\",\n            \"duration\":\"PT45S\"\n         },\n         \"workspaceId\":\"1232567898\",\n         \"isLocked\":false,\n         \"hourlyRate\":null,\n         \"costRate\":null,\n         \"customFieldValues\":[\n            \n         ],\n         \"project\":{\n            \"name\":\"Ticket 4209 - Not so Clever Admin [4066632296]\",\n            \"clientId\":\"\",\n            \"workspaceId\":\"1232567898\",\n            \"billable\":true,\n            \"estimate\":{\n               \"estimate\":\"PT0S\",\n               \"type\":\"AUTO\"\n            },\n            \"color\":\"#00BCD4\",\n            \"archived\":false,\n            \"clientName\":\"\",\n            \"duration\":\"PT0S\",\n            \"note\":\"\",\n            \"activeEstimate\":\"NONE\",\n            \"timeEstimate\":{\n               \"estimate\":0,\n               \"type\":\"AUTO\",\n               \"resetOption\":null\n            },\n            \"budgetEstimate\":null,\n            \"id\":\"5658785125\",\n            \"public\":true,\n            \"template\":false\n         },\n         \"task\":null,\n         \"user\":{\n            \"id\":\"12345678\",\n            \"name\":\"Clever Technician\",\n            \"status\":\"ACTIVE\"\n         },\n         \"tags\":[\n            \n         ]\n      }\n   }\n  }\n]"
          },
          "name": "Function",
          "type": "n8n-nodes-base.function",
          "typeVersion": 1,
          "position": [
            510,
            300
          ],
          "notesInFlow": true,
          "notes": "Mockup webhook"
        },
        {
          "parameters": {
            "keepOnlySet": true,
            "values": {
              "string": [
                {
                  "name": "Clever Technician",
                  "value": "56234"
                },
                {
                  "name": "Stupid Technician",
                  "value": "62134"
                }
              ]
            },
            "options": {}
          },
          "name": "Set",
          "type": "n8n-nodes-base.set",
          "typeVersion": 1,
          "position": [
            760,
            290
          ]
        },
        {
          "parameters": {
            "functionCode": "\nconst results = [];\n\nconst user = $node[\"Function\"].json[\"body\"][\"user\"];\n\nconst persons = items[0].json\n\nfor (key of Object.keys(persons)) {\n  if (key === user.name) {\n    results.push({ json: { id: persons[key], name: key } })\n  }\n}\n\nreturn results;"
          },
          "name": "Function1",
          "type": "n8n-nodes-base.function",
          "typeVersion": 1,
          "position": [
            1010,
            290
          ]
        }
      ],
      "connections": {
        "Start": {
          "main": [
            [
              {
                "node": "Function",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Function": {
          "main": [
            [
              {
                "node": "Set",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Set": {
          "main": [
            [
              {
                "node": "Function1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      }
    }

Yup, that did it! Thanks @RicardoE105!