or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

constants.mddata-proxy.mderror-handling.mdexpression-system.mdextension-system.mdgraph-utilities.mdindex.mdnode-execution.mdspecialized-modules.mdtype-guards.mdtype-validation.mdutilities.mdworkflow-management.md

node-execution.mddocs/

0

# Node Execution

1

2

Execution contexts and helper functions that provide nodes with access to workflow data, credentials, HTTP requests, and other runtime services required for node operation.

3

4

## Capabilities

5

6

### Execution Function Contexts

7

8

Different execution contexts for various node types and execution scenarios.

9

10

```typescript { .api }

11

/**

12

* Main node execution context interface

13

*/

14

interface IExecuteFunctions {

15

/**

16

* Get execution context for specific type

17

* @param type - Context type (node, workflow, etc.)

18

* @returns Context object

19

*/

20

getContext(type: string): IContextObject;

21

22

/**

23

* Get decrypted credentials for node

24

* @param type - Credential type name

25

* @returns Decrypted credential data

26

*/

27

getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;

28

29

/**

30

* Get input data from connected nodes

31

* @param inputIndex - Input connection index (default: 0)

32

* @returns Array of input data items

33

*/

34

getInputData(inputIndex?: number): INodeExecutionData[];

35

36

/**

37

* Get current node configuration

38

* @returns Current node object

39

*/

40

getNode(): INode;

41

42

/**

43

* Get current workflow instance

44

* @returns Workflow object

45

*/

46

getWorkflow(): Workflow;

47

48

/**

49

* Get node parameter value with expression resolution

50

* @param parameterName - Parameter name

51

* @param itemIndex - Current item index

52

* @param fallbackValue - Default value if parameter not found

53

* @returns Resolved parameter value

54

*/

55

getNodeParameter(

56

parameterName: string,

57

itemIndex: number,

58

fallbackValue?: any

59

): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[];

60

61

/**

62

* Get timezone for execution

63

* @returns Timezone string

64

*/

65

getTimezone(): string;

66

67

/**

68

* Get current execution mode

69

* @returns Execution mode

70

*/

71

getMode(): WorkflowExecuteMode;

72

73

/**

74

* Helper functions for common operations

75

*/

76

helpers: IExecuteHelperFunctions;

77

78

/**

79

* Continue execution on failure flag

80

* @returns Boolean indicating continue on fail

81

*/

82

continueOnFail(): boolean;

83

84

/**

85

* Get additional data for execution

86

* @returns Additional execution data

87

*/

88

getExecuteData(): IExecuteData;

89

}

90

91

/**

92

* Single function execution context

93

*/

94

interface IExecuteSingleFunctions {

95

getContext(type: string): IContextObject;

96

getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;

97

getInputData(): INodeExecutionData;

98

getNode(): INode;

99

getWorkflow(): Workflow;

100

getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue;

101

getTimezone(): string;

102

getMode(): WorkflowExecuteMode;

103

helpers: IExecuteSingleHelperFunctions;

104

continueOnFail(): boolean;

105

}

106

107

/**

108

* Pagination-enabled execution context

109

*/

110

interface IExecutePaginationFunctions extends IExecuteFunctions {

111

/**

112

* Make paginated request with automatic continuation

113

* @param requestOptions - HTTP request configuration

114

* @param itemsPerPage - Items per page limit

115

* @returns Paginated response data

116

*/

117

makeRequestWithPagination<T>(

118

requestOptions: IHttpRequestOptions,

119

itemsPerPage?: number

120

): Promise<T[]>;

121

}

122

```

123

124

### Helper Functions

125

126

Comprehensive helper functions for HTTP requests, data manipulation, and common operations.

127

128

```typescript { .api }

129

interface IExecuteHelperFunctions {

130

/**

131

* Make HTTP request with credential authentication

132

* @param requestOptions - HTTP request configuration

133

* @returns HTTP response data

134

*/

135

httpRequest(requestOptions: IHttpRequestOptions): Promise<any>;

136

137

/**

138

* Make authenticated HTTP request using credentials

139

* @param credentialsType - Type of credentials to use

140

* @param requestOptions - HTTP request configuration

141

* @returns HTTP response data

142

*/

143

httpRequestWithAuthentication(

144

credentialsType: string,

145

requestOptions: IHttpRequestOptions

146

): Promise<any>;

147

148

/**

149

* Return data as JSON array format

150

* @param jsonData - Array of objects to return

151

* @returns Formatted execution data

152

*/

153

returnJsonArray(jsonData: IDataObject[]): INodeExecutionData[];

154

155

/**

156

* Prepare output data structure

157

* @param outputData - Data to prepare for output

158

* @returns Prepared node execution data

159

*/

160

prepareOutputData(outputData: INodeExecutionData[]): INodeExecutionData[];

161

162

/**

163

* Log message with node context

164

* @param message - Message to log

165

* @param level - Log level

166

*/

167

logNodeOutput(message: string, level?: LogLevel): void;

168

169

/**

170

* Get binary data stream

171

* @param itemIndex - Item index for binary data

172

* @param propertyName - Binary property name

173

* @returns Binary data stream

174

*/

175

getBinaryDataStream(itemIndex: number, propertyName: string): Readable;

176

177

/**

178

* Prepare binary data for output

179

* @param binaryData - Binary data buffer

180

* @param filePath - File path for binary data

181

* @param mimeType - MIME type of binary data

182

* @returns Binary data configuration

183

*/

184

prepareBinaryData(

185

binaryData: Buffer,

186

filePath?: string,

187

mimeType?: string

188

): Promise<IBinaryData>;

189

190

/**

191

* Create deferred promise for async operations

192

* @returns Deferred promise instance

193

*/

194

createDeferredPromise<T>(): IDeferredPromise<T>;

195

}

196

```

197

198

### HTTP Request Configuration

199

200

Configuration interfaces for HTTP requests and authentication.

201

202

```typescript { .api }

203

interface IHttpRequestOptions {

204

url: string;

205

method?: IHttpRequestMethods;

206

body?: any;

207

qs?: IDataObject;

208

headers?: IDataObject;

209

auth?: IHttpRequestAuth;

210

timeout?: number;

211

encoding?: string | null;

212

json?: boolean;

213

gzip?: boolean;

214

resolveWithFullResponse?: boolean;

215

simple?: boolean;

216

proxy?: string;

217

strictSSL?: boolean;

218

rejectUnauthorized?: boolean;

219

followRedirect?: boolean;

220

followAllRedirects?: boolean;

221

maxRedirects?: number;

222

returnFullResponse?: boolean;

223

}

224

225

type IHttpRequestMethods =

226

| 'DELETE'

227

| 'GET'

228

| 'HEAD'

229

| 'PATCH'

230

| 'POST'

231

| 'PUT';

232

233

interface IHttpRequestAuth {

234

username: string;

235

password: string;

236

sendImmediately?: boolean;

237

}

238

```

239

240

### Trigger and Webhook Contexts

241

242

Specialized execution contexts for trigger nodes and webhook handling.

243

244

```typescript { .api }

245

/**

246

* Trigger function execution context

247

*/

248

interface ITriggerFunctions {

249

getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;

250

getNode(): INode;

251

getWorkflow(): Workflow;

252

getMode(): WorkflowExecuteMode;

253

getTimezone(): string;

254

255

/**

256

* Emit trigger event with data

257

* @param data - Trigger data to emit

258

* @param responsePromise - Optional response promise

259

*/

260

emit(

261

data: INodeExecutionData[][],

262

responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>

263

): void;

264

265

helpers: ITriggerHelperFunctions;

266

}

267

268

/**

269

* Webhook function execution context

270

*/

271

interface IWebhookFunctions {

272

getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;

273

getNode(): INode;

274

getWorkflow(): Workflow;

275

getMode(): WorkflowExecuteMode;

276

277

/**

278

* Get webhook request object

279

* @returns Express request object

280

*/

281

getRequestObject(): express.Request;

282

283

/**

284

* Get webhook response object

285

* @returns Express response object

286

*/

287

getResponseObject(): express.Response;

288

289

/**

290

* Get request body data

291

* @returns Parsed request body

292

*/

293

getBodyData(): IDataObject;

294

295

/**

296

* Get request headers

297

* @returns Request headers object

298

*/

299

getHeaderData(): IDataObject;

300

301

/**

302

* Get URL parameters

303

* @returns URL parameters object

304

*/

305

getParamsData(): IDataObject;

306

307

/**

308

* Get query parameters

309

* @returns Query parameters object

310

*/

311

getQueryData(): IDataObject;

312

313

helpers: IWebhookHelperFunctions;

314

}

315

```

316

317

### Load Options Context

318

319

Context for dynamic option loading in node parameter configuration.

320

321

```typescript { .api }

322

/**

323

* Load options function context

324

*/

325

interface ILoadOptionsFunctions {

326

getCredentials(type: string): Promise<ICredentialDataDecryptedObject>;

327

getNode(): INode;

328

getWorkflow(): Workflow;

329

330

/**

331

* Get current node parameter values

332

* @returns Current parameter values

333

*/

334

getCurrentNodeParameters(): INodeParameters;

335

336

/**

337

* Get parameter value by name

338

* @param parameterName - Parameter name

339

*/

340

getCurrentNodeParameter(parameterName: string): NodeParameterValue | undefined;

341

342

helpers: ILoadOptionsHelperFunctions;

343

}

344

345

/**

346

* Node property options for dynamic loading

347

*/

348

interface INodePropertyOptions {

349

name: string;

350

value: string | number | boolean;

351

description?: string;

352

action?: string;

353

}

354

```

355

356

**Usage Examples:**

357

358

```typescript

359

import { IExecuteFunctions, INodeExecutionData, IDataObject } from "n8n-workflow";

360

361

// Basic node execution function

362

export async function execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {

363

const items = this.getInputData();

364

const returnData: INodeExecutionData[] = [];

365

366

for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {

367

try {

368

// Get node parameters

369

const apiUrl = this.getNodeParameter('apiUrl', itemIndex) as string;

370

const method = this.getNodeParameter('method', itemIndex, 'GET') as string;

371

372

// Get credentials

373

const credentials = await this.getCredentials('httpBasicAuth');

374

375

// Make HTTP request

376

const requestOptions = {

377

url: apiUrl,

378

method: method as IHttpRequestMethods,

379

auth: {

380

username: credentials.user as string,

381

password: credentials.password as string,

382

},

383

json: true,

384

};

385

386

const response = await this.helpers.httpRequest(requestOptions);

387

388

// Return data

389

returnData.push({

390

json: response,

391

pairedItem: itemIndex,

392

});

393

394

} catch (error) {

395

if (this.continueOnFail()) {

396

returnData.push({

397

json: { error: error.message },

398

pairedItem: itemIndex,

399

});

400

} else {

401

throw error;

402

}

403

}

404

}

405

406

return [returnData];

407

}

408

409

// Webhook node example

410

export async function webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {

411

const bodyData = this.getBodyData();

412

const headerData = this.getHeaderData();

413

const queryData = this.getQueryData();

414

415

// Process webhook data

416

const responseData: IDataObject = {

417

body: bodyData,

418

headers: headerData,

419

query: queryData,

420

receivedAt: new Date().toISOString(),

421

};

422

423

return {

424

workflowData: [

425

[

426

{

427

json: responseData,

428

},

429

],

430

],

431

};

432

}

433

434

// Load options example

435

export async function loadOptions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {

436

const credentials = await this.getCredentials('myApiCredentials');

437

438

const requestOptions = {

439

url: 'https://api.example.com/options',

440

headers: {

441

'Authorization': `Bearer ${credentials.apiKey}`,

442

},

443

json: true,

444

};

445

446

const response = await this.helpers.httpRequest!(requestOptions);

447

448

return response.options.map((option: any) => ({

449

name: option.label,

450

value: option.id,

451

description: option.description,

452

}));

453

}

454

```