0
# Workflow Management
1
2
Core workflow creation, execution, and management functionality including node orchestration, data flow control, and workflow lifecycle management.
3
4
## Capabilities
5
6
### Workflow Class
7
8
Main workflow execution engine that manages node execution, data flow, and workflow state.
9
10
```typescript { .api }
11
/**
12
* Main workflow execution engine class
13
*/
14
class Workflow {
15
id?: string;
16
name: string;
17
nodes: INode[];
18
connections: IConnections;
19
active: boolean;
20
nodeTypes: INodeTypes;
21
staticData: IDataObject;
22
settings: IWorkflowSettings;
23
24
constructor(parameters: IWorkflowBase);
25
26
/**
27
* Execute the workflow
28
* @param mode - Execution mode (manual, trigger, etc.)
29
* @param startNode - Optional starting node name
30
* @returns Execution result data
31
*/
32
execute(
33
mode: WorkflowExecuteMode,
34
startNode?: string
35
): Promise<IRunExecutionData>;
36
37
/**
38
* Get a specific node by name
39
* @param nodeName - Name of the node to retrieve
40
* @returns Node object or null if not found
41
*/
42
getNode(nodeName: string): INode | null;
43
44
/**
45
* Get all nodes in the workflow
46
* @returns Array of all nodes
47
*/
48
getNodes(): INode[];
49
50
/**
51
* Get all connections in the workflow
52
* @returns Connections object
53
*/
54
getConnections(): IConnections;
55
56
/**
57
* Check if workflow is active
58
* @returns Boolean indicating if workflow is active
59
*/
60
isActive(): boolean;
61
62
/**
63
* Rename a node and update all references
64
* @param currentName - Current node name
65
* @param newName - New node name
66
*/
67
renameNode(currentName: string, newName: string): void;
68
}
69
```
70
71
### Workflow Configuration Interfaces
72
73
Core interfaces for defining workflow structure and behavior.
74
75
```typescript { .api }
76
interface IWorkflowBase {
77
id?: string;
78
name: string;
79
nodes: INode[];
80
connections: IConnections;
81
active: boolean;
82
nodeTypes: INodeTypes;
83
staticData?: IDataObject;
84
settings?: IWorkflowSettings;
85
}
86
87
interface INode {
88
id?: string;
89
name: string;
90
type: string;
91
typeVersion: number;
92
position: [number, number];
93
parameters: INodeParameters;
94
credentials?: INodeCredentialsDetails;
95
disabled?: boolean;
96
notes?: string;
97
continueOnFail?: boolean;
98
alwaysOutputData?: boolean;
99
executeOnce?: boolean;
100
retryOnFail?: boolean;
101
maxTries?: number;
102
waitBetweenTries?: number;
103
onError?: string;
104
}
105
106
interface IConnections {
107
[key: string]: {
108
[type: string]: IConnection[][];
109
};
110
}
111
112
interface IConnection {
113
node: string;
114
type: NodeConnectionType;
115
index: number;
116
}
117
118
interface IWorkflowSettings {
119
timezone?: string;
120
saveDataErrorExecution?: string;
121
saveDataSuccessExecution?: string;
122
saveManualExecutions?: boolean;
123
callerPolicy?: string;
124
errorWorkflow?: string;
125
executionTimeout?: number;
126
}
127
```
128
129
### Node Types and Parameters
130
131
Interfaces for defining node types and their parameters.
132
133
```typescript { .api }
134
interface INodeTypes {
135
nodeTypes: {
136
[key: string]: INodeType;
137
};
138
init?(nodeTypes?: INodeTypes): Promise<void>;
139
}
140
141
interface INodeType {
142
description: INodeTypeDescription;
143
execute?(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
144
poll?(this: IPollFunctions): Promise<INodeExecutionData[][] | null>;
145
trigger?(this: ITriggerFunctions): Promise<ITriggerResponse | undefined>;
146
webhook?(this: IWebhookFunctions): Promise<IWebhookResponseData>;
147
}
148
149
interface INodeParameters {
150
[key: string]:
151
| string
152
| number
153
| boolean
154
| undefined
155
| null
156
| IDataObject
157
| INodeParameters
158
| INodeParameters[]
159
| NodeParameterValue
160
| NodeParameterValue[];
161
}
162
```
163
164
### Execution Data Structures
165
166
Data structures for workflow and node execution results.
167
168
```typescript { .api }
169
interface IRunExecutionData {
170
resultData: IRunData;
171
startData: IStartRunData;
172
executionData?: IExecutionData;
173
}
174
175
interface IRunData {
176
[key: string]: ITaskData[];
177
}
178
179
interface ITaskData {
180
startTime: number;
181
executionTime: number;
182
executionStatus?: ExecutionStatus;
183
data?: ITaskDataConnections;
184
error?: ExecutionError;
185
source: Array<ISourceData | null> | null;
186
}
187
188
interface INodeExecutionData {
189
[key: string]: any;
190
json: IDataObject;
191
binary?: IBinaryKeyData;
192
pairedItem?: IPairedItemData | IPairedItemData[] | number;
193
error?: ExecutionError;
194
}
195
```
196
197
**Usage Examples:**
198
199
```typescript
200
import { Workflow, INode, IConnections } from "n8n-workflow";
201
202
// Create nodes
203
const nodes: INode[] = [
204
{
205
id: "start-node",
206
name: "Start",
207
type: "n8n-nodes-base.start",
208
typeVersion: 1,
209
position: [100, 200],
210
parameters: {}
211
},
212
{
213
id: "webhook-node",
214
name: "Webhook",
215
type: "n8n-nodes-base.webhook",
216
typeVersion: 1,
217
position: [300, 200],
218
parameters: {
219
httpMethod: "GET",
220
path: "webhook-test"
221
}
222
}
223
];
224
225
// Define connections
226
const connections: IConnections = {
227
"Start": {
228
"main": [
229
[{ "node": "Webhook", "type": "main", "index": 0 }]
230
]
231
}
232
};
233
234
// Create workflow
235
const workflow = new Workflow({
236
id: "example-workflow",
237
name: "Example Workflow",
238
nodes,
239
connections,
240
active: true,
241
nodeTypes: nodeTypesInstance,
242
staticData: {}
243
});
244
245
// Get specific node
246
const startNode = workflow.getNode("Start");
247
if (startNode) {
248
console.log(`Found node: ${startNode.name}`);
249
}
250
251
// Check if workflow is active
252
if (workflow.isActive()) {
253
console.log("Workflow is active and ready to execute");
254
}
255
256
// Execute workflow
257
const executionResult = await workflow.execute("manual");
258
console.log("Execution completed:", executionResult);
259
```