-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add create workflow execution functionality with parameters and… #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { INodeProperties } from 'n8n-workflow'; | ||
|
|
||
| export const createWorkflowExecutionDescription: INodeProperties[] = [ | ||
| { | ||
| displayName: 'Workflow ID', | ||
| name: 'workflowId', | ||
| type: 'string', | ||
| required: true, | ||
| default: '', | ||
| displayOptions: { | ||
| show: { | ||
| operation: ['createWorkflowExecution'], | ||
| }, | ||
| }, | ||
| description: 'The ID of the workflow to execute', | ||
| }, | ||
| { | ||
| displayName: 'Customer Lead ID', | ||
| name: 'customerLeadId', | ||
| type: 'string', | ||
| required: true, | ||
| default: '', | ||
| displayOptions: { | ||
| show: { | ||
| operation: ['createWorkflowExecution'], | ||
| }, | ||
| }, | ||
| description: 'Customer lead identifier', | ||
| }, | ||
| { | ||
| displayName: 'Primary Phone', | ||
| name: 'primaryPhone', | ||
| type: 'string', | ||
| required: true, | ||
| default: '', | ||
| displayOptions: { | ||
| show: { | ||
| operation: ['createWorkflowExecution'], | ||
| }, | ||
| }, | ||
| description: 'Primary phone number for the execution', | ||
| }, | ||
| { | ||
| displayName: 'Zipcode', | ||
| name: 'zipcode', | ||
| type: 'string', | ||
| default: '', | ||
| displayOptions: { | ||
| show: { | ||
| operation: ['createWorkflowExecution'], | ||
| }, | ||
| }, | ||
| description: 'Zipcode for the execution', | ||
| }, | ||
| { | ||
| displayName: 'State', | ||
| name: 'state', | ||
| type: 'string', | ||
| default: '', | ||
| displayOptions: { | ||
| show: { | ||
| operation: ['createWorkflowExecution'], | ||
| }, | ||
| }, | ||
| description: 'State for the execution', | ||
| }, | ||
| { | ||
| displayName: 'Forwarding Phone Number', | ||
| name: 'forwardingPhoneNumber', | ||
| type: 'string', | ||
| default: '', | ||
| displayOptions: { | ||
| show: { | ||
| operation: ['createWorkflowExecution'], | ||
| }, | ||
| }, | ||
| description: 'Phone number to forward calls to', | ||
| }, | ||
| { | ||
| displayName: 'Additional Fields', | ||
| name: 'additionalFields', | ||
| type: 'collection', | ||
| placeholder: 'Add Field', | ||
| default: {}, | ||
| displayOptions: { | ||
| show: { | ||
| operation: ['createWorkflowExecution'], | ||
| }, | ||
| }, | ||
| options: [ | ||
| { | ||
| displayName: 'First Name', | ||
| name: 'firstName', | ||
| type: 'string', | ||
| default: '', | ||
| description: 'First name for metadata', | ||
| }, | ||
| { | ||
| displayName: 'Last Name', | ||
| name: 'lastName', | ||
| type: 'string', | ||
| default: '', | ||
| description: 'Last name for metadata', | ||
| }, | ||
| { | ||
| displayName: 'Variables (JSON)', | ||
| name: 'variables', | ||
| type: 'json', | ||
| default: '{}', | ||
| description: 'Variables for the execution as JSON object', | ||
| }, | ||
| { | ||
| displayName: 'Additional Metadata (JSON)', | ||
| name: 'additionalMetadata', | ||
| type: 'json', | ||
| default: '{}', | ||
| description: 'Additional metadata fields as JSON object', | ||
| }, | ||
| ], | ||
| }, | ||
| ]; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,121 @@ | ||||||||||||||||||||||||||||||||||||||
| import { IExecuteFunctions, INodeExecutionData, NodeOperationError } from 'n8n-workflow'; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| export async function executeCreateWorkflowExecution( | ||||||||||||||||||||||||||||||||||||||
| this: IExecuteFunctions, | ||||||||||||||||||||||||||||||||||||||
| i: number, | ||||||||||||||||||||||||||||||||||||||
| baseURL: string, | ||||||||||||||||||||||||||||||||||||||
| ): Promise<INodeExecutionData> { | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| console.log('Starting workflow execution creation...'); | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Remove console.log statements in production code |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Get required parameters | ||||||||||||||||||||||||||||||||||||||
| const workflowId = this.getNodeParameter('workflowId', i) as string; | ||||||||||||||||||||||||||||||||||||||
| const customerLeadId = this.getNodeParameter('customerLeadId', i) as string; | ||||||||||||||||||||||||||||||||||||||
| const primaryPhone = this.getNodeParameter('primaryPhone', i) as string; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Get optional parameters | ||||||||||||||||||||||||||||||||||||||
| const zipcode = this.getNodeParameter('zipcode', i, null) as string | null; | ||||||||||||||||||||||||||||||||||||||
| const state = this.getNodeParameter('state', i, null) as string | null; | ||||||||||||||||||||||||||||||||||||||
| const forwardingPhoneNumber = this.getNodeParameter('forwardingPhoneNumber', i, null) as | ||||||||||||||||||||||||||||||||||||||
| | string | ||||||||||||||||||||||||||||||||||||||
| | null; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Get additional fields | ||||||||||||||||||||||||||||||||||||||
| const additionalFields = this.getNodeParameter('additionalFields', i, {}) as Record< | ||||||||||||||||||||||||||||||||||||||
| string, | ||||||||||||||||||||||||||||||||||||||
| unknown | ||||||||||||||||||||||||||||||||||||||
| >; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| console.log('Basic parameters:', { workflowId, customerLeadId, primaryPhone, zipcode, state }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Build request body | ||||||||||||||||||||||||||||||||||||||
| const body: Record<string, unknown> = { | ||||||||||||||||||||||||||||||||||||||
| customerLeadId, | ||||||||||||||||||||||||||||||||||||||
| primaryPhone, | ||||||||||||||||||||||||||||||||||||||
| zipcode, | ||||||||||||||||||||||||||||||||||||||
| state, | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Including null values in API payload might cause issues - consider excluding null fields entirely
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Only include forwardingPhoneNumber if it's provided | ||||||||||||||||||||||||||||||||||||||
| if (forwardingPhoneNumber) { | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Inconsistent handling - empty strings are falsy and won't be included, but null values in zipcode/state are included in payload |
||||||||||||||||||||||||||||||||||||||
| body.forwardingPhoneNumber = forwardingPhoneNumber; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Handle variables (JSON) | ||||||||||||||||||||||||||||||||||||||
| if (additionalFields.variables) { | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| body.variables = | ||||||||||||||||||||||||||||||||||||||
| typeof additionalFields.variables === 'string' | ||||||||||||||||||||||||||||||||||||||
| ? JSON.parse(additionalFields.variables as string) | ||||||||||||||||||||||||||||||||||||||
| : additionalFields.variables; | ||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||
| throw new NodeOperationError(this.getNode(), 'Invalid JSON in Variables field', { | ||||||||||||||||||||||||||||||||||||||
| itemIndex: i, | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| body.variables = {}; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Handle metadata | ||||||||||||||||||||||||||||||||||||||
| const metadata: Record<string, unknown> = {}; | ||||||||||||||||||||||||||||||||||||||
| if (additionalFields.firstName) { | ||||||||||||||||||||||||||||||||||||||
| metadata.firstName = additionalFields.firstName; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (additionalFields.lastName) { | ||||||||||||||||||||||||||||||||||||||
| metadata.lastName = additionalFields.lastName; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // Add any additional metadata fields | ||||||||||||||||||||||||||||||||||||||
| if (additionalFields.additionalMetadata) { | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| const additionalMetadata = | ||||||||||||||||||||||||||||||||||||||
| typeof additionalFields.additionalMetadata === 'string' | ||||||||||||||||||||||||||||||||||||||
| ? JSON.parse(additionalFields.additionalMetadata as string) | ||||||||||||||||||||||||||||||||||||||
| : additionalFields.additionalMetadata; | ||||||||||||||||||||||||||||||||||||||
| Object.assign(metadata, additionalMetadata); | ||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||
| throw new NodeOperationError(this.getNode(), 'Invalid JSON in Additional Metadata field', { | ||||||||||||||||||||||||||||||||||||||
| itemIndex: i, | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| body.metadata = metadata; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| console.log('Preparing API request with execution data:', JSON.stringify(body, null, 2)); | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Remove console.log statements in production code |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| const response = await this.helpers.httpRequestWithAuthentication.call(this, 'featherApi', { | ||||||||||||||||||||||||||||||||||||||
| method: 'POST', | ||||||||||||||||||||||||||||||||||||||
| url: `${baseURL}/api/v1/workflow/${workflowId}/execution`, | ||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||
| 'Content-Type': 'application/json', | ||||||||||||||||||||||||||||||||||||||
| accept: 'application/json, text/plain, */*', | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| body, | ||||||||||||||||||||||||||||||||||||||
| json: true, | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| console.log('Workflow execution created successfully:', JSON.stringify(response, null, 2)); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||
| json: response, | ||||||||||||||||||||||||||||||||||||||
| pairedItem: { | ||||||||||||||||||||||||||||||||||||||
| item: i, | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
| } catch (apiError) { | ||||||||||||||||||||||||||||||||||||||
| console.error('API request failed:', apiError); | ||||||||||||||||||||||||||||||||||||||
| console.error('Request details:', { | ||||||||||||||||||||||||||||||||||||||
| url: `${baseURL}/api/v1/workflow/${workflowId}/execution`, | ||||||||||||||||||||||||||||||||||||||
| workflowId, | ||||||||||||||||||||||||||||||||||||||
| body, | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
| throw apiError; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||
| console.error('Error in workflow execution creation:', error); | ||||||||||||||||||||||||||||||||||||||
| throw error; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Missing credentials parameter in executeCreateWorkflowExecution call - other operations like getWorkflows and dispatchPhoneCall pass credentials as the third parameter