De / Activate Workflow node

The idea is simple:

to be able to activate / deactivate a workflow by triggering a node (Kinda like the execute workflow) instead of doing it manually.

I’m talking about this button:
Screenshot 2021-12-16 at 19.16.03

My use case:

And this is exactly what I picture.

So we could have workflow activated or deactivated on specific trigger.

Some workflows got Cron or Interval nodes and have to be active to run.
I wanna be able to activate/deactivate those workflows on specific conditions.

Someone filling up a form or whatever. So I won’t have to go on n8n to do it manually.

I’m sick of having some interval workflows executing endlessly because I have to turn them off manually…

There is a workaround for this by calling the n8n API with the HTTP node. Try this

Workflow JSON
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [],
          "boolean": [
            {
              "value1": "={{$json[\"data\"][\"active\"]}}",
              "value2": true
            }
          ]
        }
      },
      "name": "Active?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        700,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "=http://localhost:5678/rest/workflows/{{$node[\"WorkflowID\"].json[\"workflowID\"]}}",
        "options": {}
      },
      "name": "Get Workflow",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        500,
        300
      ],
      "credentials": {
        "httpBasicAuth": {
          "id": "3",
          "name": "n8n local"
        }
      }
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "requestMethod": "PATCH",
        "url": "=http://localhost:5678/rest/workflows/{{$node[\"WorkflowID\"].json[\"workflowID\"]}}",
        "responseFormat": "string",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\"active\": true}"
      },
      "name": "Activate",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        980,
        380
      ],
      "credentials": {
        "httpBasicAuth": {
          "id": "3",
          "name": "n8n local"
        }
      }
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "workflowID",
              "value": 18
            }
          ]
        },
        "options": {}
      },
      "name": "WorkflowID",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        300,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "requestMethod": "PATCH",
        "url": "=http://localhost:5678/rest/workflows/{{$node[\"WorkflowID\"].json[\"workflowID\"]}}",
        "responseFormat": "string",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\"active\": false}"
      },
      "name": "Deactivate",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        980,
        220
      ],
      "credentials": {
        "httpBasicAuth": {
          "id": "3",
          "name": "n8n local"
        }
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "WorkflowID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Active?": {
      "main": [
        [
          {
            "node": "Deactivate",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Activate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Workflow": {
      "main": [
        [
          {
            "node": "Active?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WorkflowID": {
      "main": [
        [
          {
            "node": "Get Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
5 Likes

Wow @pemontto !!

Thanks, it works like a charm! :pray:

Now I can’t wait to see this being implemented.

For now, I’ll just tweak this a bit so I can use this as a sub workflow and can call it with the Execute Workflow node :+1:

1 Like