Authorization is required when checking if existing flows are running

Hello, I used the solution there provided by @jan to check if other flows are running. However I’m getting this error. Authorization is required! All of my other internal http request node work fine for starting flows, so I’m unsure what the issue is.


{
"status": "rejected",
"reason": {
"name": "StatusCodeError",
"statusCode": 401,
"message": "401 - {"code":401,"message":"Authorization is required!"}",
"error": {
"code": 401,
"message": "Authorization is required!"
},
"options": {
"timeout": 3600000,
"headers": {...}, // 1 keys
"method": "GET",
"uri": "http://localhost:5678/rest/executions-current",
"gzip": true,
"rejectUnauthorized": true,
"json": true,
"simple": true,
"resolveWithFullResponse": false,
"transform2xxOnly": false
},
"response": {
"statusCode": 401,
"body": {...}, // 2 keys
"headers": {...}, // 7 keys
"request": {...} // 3 keys
}
}
}

My first guess is that you’d have basic auth configured for n8n so it’s expecting a username and password. Have you tried adding these to the HTTP Request node (under AuthenticationBasic Auth and then Credential for Basic AuthCreate New)?

It worked. Thanks.

1 Like

But it seems I have another issue now. I added to the flow “1. Clean Up (Search)” but as you can see in the screenshot, it triggered even though 2 other flows were already running.


{
  "nodes": [
    {
      "parameters": {
        "interval": 5,
        "unit": "minutes"
      },
      "name": "Interval1",
      "type": "n8n-nodes-base.interval",
      "typeVersion": 1,
      "position": [
        -980,
        -320
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "http://localhost:5678/rest/executions-current",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        -740,
        -340
      ],
      "credentials": {
        "httpBasicAuth": {
          "id": "22",
          "name": "n8n Incluzion"
        }
      }
    },
    {
      "parameters": {},
      "name": "Is running",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -140,
        -440
      ]
    },
    {
      "parameters": {},
      "name": "Is NOT running",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -120,
        -220
      ]
    },
    {
      "parameters": {
        "functionCode": "const executions = items[0].json.data.filter(execution => execution.workflowId.toString() === $workflow.id.toString());\n\nreturn [\n  {\n    json: {\n      isActive: executions.length > 1,\n    }\n  }\n];"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -540,
        -340
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json[\"isActive\"]}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -340,
        -340
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        100,
        -360
      ]
    }
  ],
  "connections": {
    "Interval1": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is running": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "IF1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF1": {
      "main": [
        [
          {
            "node": "Is running",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Is NOT running",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

The example you have shared would only check if the current workflow is already executing more than once, if I see that correctly.

Based on your screenshot I understand however you want to check whether any other workflow is running? If so, you wouldn’t need to filter for the current workflow ID. You could just check whether there are more than 1 workflows running in total. Simply remove the filter part .filter(execution => execution.workflowId.toString() === $workflow.id.toString()) from your Function.

Awesome. Thanks for the quick response. That worked!

1 Like

One last question. This flow doesn’t detect if a workflow is active but in “wait” status. Can you help me with that?

So from quickly trying this out I can confirm the endpoint you are using does not return any workflows in Waiting status if that’s what you were looking at.

To find these, you could use the http://localhost:5678/rest/executions endpoint which is used when opening the executions list from the left sidebar:
image

This example workflow would find waiting workflows when testing this:

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:5678/rest/executions",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "filter",
              "value": "{}"
            },
            {
              "name": "limit",
              "value": "30"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data.results",
        "options": {}
      },
      "name": "Item Lists",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n  json: {\n    waiting_workflows: items.filter(e => e.json.finished === false && e.json.waitTill).length\n  }\n}]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Item Lists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Item Lists": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

image

1 Like

Unfortunately this isn’t working for me. I have 2 waiting executions however no executions are detected as waiting. I’ve noticed that in the executions model waiting executions don’t show when “any status” is selected, only when the “waiting” filter is selected. Maybe there is an additional parameter that is needed in the url as well.

After a version update, the waiting flows are now detected.

1 Like