Documentation
¶
Overview ¶
Copyright © 2025 Eden Reich
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2025 Eden Reich ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2025 Eden Reich ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2025 Eden Reich ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2025 Eden Reich ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2025 Eden Reich ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Variables
- func ExecuteOrDryRun(cmd *cobra.Command, dryRun bool, dryRunMsg string, fn func() (string, error)) error
- func ExtractWorkflowIDFromFile(filePath string) (string, error)
- func HandleTagUpdates(client n8n.ClientInterface, cmd *cobra.Command, workflow *n8n.Workflow, ...) error
- func PruneWorkflows(client n8n.ClientInterface, cmd *cobra.Command, ...) error
- func RefreshWorkflows(cmd *cobra.Command, args []string) error
- func RefreshWorkflowsWithClient(cmd *cobra.Command, client n8n.ClientInterface, directory string, dryRun bool, ...) error
- func SyncWorkflows(cmd *cobra.Command, args []string) error
- type ActivateCommand
- type DeactivateCommand
- type ExecutionHandler
- type WorkflowChange
- type WorkflowResult
- func CreateWorkflow(client n8n.ClientInterface, cmd *cobra.Command, workflow *n8n.Workflow, ...) (WorkflowResult, error)
- func CreateWorkflowWithID(client n8n.ClientInterface, cmd *cobra.Command, workflow *n8n.Workflow, ...) (WorkflowResult, error)
- func ProcessWorkflowFile(client n8n.ClientInterface, cmd *cobra.Command, filePath string, dryRun bool, ...) (WorkflowResult, error)
- func UpdateWorkflow(client n8n.ClientInterface, cmd *cobra.Command, workflow *n8n.Workflow, ...) (WorkflowResult, error)
Constants ¶
This section is empty.
Variables ¶
var ActivateCmd = &cobra.Command{ Use: "activate WORKFLOW_ID", Short: "Activate a workflow by ID", Long: `Activate a workflow in n8n by its ID, making it ready to be triggered by events.`, Args: cobra.ExactArgs(1), RunE: activateWorkflow, }
ActivateCmd represents the activate command
var DeactivateCmd = &cobra.Command{ Use: "deactivate WORKFLOW_ID", Short: "Deactivate a workflow by ID", Long: `Deactivate a workflow in n8n by its ID, stopping it from being triggered by events.`, Args: cobra.ExactArgs(1), RunE: deactivateWorkflow, }
DeactivateCmd represents the deactivate command
var ExecutionsCmd = &cobra.Command{ Use: "executions [WORKFLOW_ID]", Short: "Get execution history for workflows", Long: `Retrieve execution history for n8n workflows. If a workflow ID is provided, only executions for that specific workflow are returned.`, RunE: func(cmd *cobra.Command, args []string) error { apiKey, ok := viper.Get("api_key").(string) if !ok || apiKey == "" { return fmt.Errorf("API key not found in configuration") } instanceURL, ok := viper.Get("instance_url").(string) if !ok || instanceURL == "" { return fmt.Errorf("instance URL not found in configuration") } client := n8n.NewClient(instanceURL, apiKey) handler := ExecutionHandler{Client: client} return handler.Handle(cmd, args) }, }
ExecutionsCmd represents the executions command
var ListCmd = &cobra.Command{ Use: "list", Short: "List JSON workflows in n8n instance", Long: `List command fetches and lists JSON workflows from a specified n8n instance.`, Args: cobra.ExactArgs(0), RunE: listWorkflows, }
listCmd represents the list command
var SyncCmd = &cobra.Command{ Use: "sync", Short: "Synchronize workflows between local files and n8n instance", Long: `Synchronizes workflow files from a local directory to an n8n instance. Examples: # Sync all workflow files from a directory n8n workflows sync --directory workflows/ # Preview changes without applying them n8n workflows sync --directory workflows/ --dry-run # Sync and remove workflows that don't exist locally n8n workflows sync --directory workflows/ --prune # Sync without refreshing local files afterward n8n workflows sync --directory workflows/ --refresh=false This command processes JSON and YAML workflow files and ensures they exist on your n8n instance: 1. Each workflow file is processed intelligently: - Workflows with IDs that exist on the server will be updated - Workflows with IDs that don't exist will be created - Workflows without IDs will be created as new - Active state (true/false) will be respected and applied 2. Common scenarios: - Development → Production: Create workflow files locally, test them, then sync to production - Backup: Store workflow configurations in a git repository for version control - Migration: Export workflows from one n8n instance and import to another - CI/CD: Automate workflow deployments in your delivery pipeline - Leverage AI-assisted development: Create workflows with Large Language Models (LLMs) and sync to n8n - streamlining workflow creation through code instead of manual UI interaction 3. File formats supported: - JSON: Standard n8n workflow export format - YAML: More readable alternative, ideal for version control 4. Additional examples: - Deploy workflows to production: n8n workflows sync --directory workflows/production/ - Migrate between environments (dev to staging): n8n workflows sync --directory workflows/dev/ --prune - Back up before a major change: mkdir -p backups/$(date +%Y%m%d) && \ n8n workflows refresh --directory backups/$(date +%Y%m%d)/ --format json - In CI/CD pipelines: n8n workflows sync --directory workflows/ --dry-run && \ n8n workflows sync --directory workflows/ 5. Options: - Use --dry-run to preview changes without applying them - Use --prune to remove remote workflows that don't exist locally - Use --refresh=false to prevent refreshing local files with remote state after sync - Use --output to specify the format (json or yaml) for refreshed workflow files - Use --all to refresh all workflows from n8n instance, not just those in the directory`, RunE: SyncWorkflows, }
syncCmd represents the sync command
Functions ¶
func ExecuteOrDryRun ¶ added in v0.4.0
func ExecuteOrDryRun(cmd *cobra.Command, dryRun bool, dryRunMsg string, fn func() (string, error)) error
ExecuteOrDryRun is a helper function that either performs an action or shows what would happen based on whether dry run mode is enabled
func ExtractWorkflowIDFromFile ¶
ExtractWorkflowIDFromFile reads a workflow file and extracts the workflow ID if present
func HandleTagUpdates ¶ added in v0.4.0
func HandleTagUpdates(client n8n.ClientInterface, cmd *cobra.Command, workflow *n8n.Workflow, workflowID string, dryRun bool) error
HandleTagUpdates updates the tags for a workflow if needed
func PruneWorkflows ¶
func PruneWorkflows(client n8n.ClientInterface, cmd *cobra.Command, localWorkflowIDs map[string]bool) error
PruneWorkflows removes workflows from n8n that are not in the local workflow files
func RefreshWorkflows ¶
RefreshWorkflows refreshes workflow files from n8n instance
func RefreshWorkflowsWithClient ¶
func RefreshWorkflowsWithClient(cmd *cobra.Command, client n8n.ClientInterface, directory string, dryRun bool, overwrite bool, output string, minimal bool, all bool) error
RefreshWorkflowsWithClient is the testable version of RefreshWorkflows that accepts a client interface
Types ¶
type ActivateCommand ¶
ActivateCommand represents the command to activate a workflow
type DeactivateCommand ¶
DeactivateCommand represents the command to deactivate a workflow
type ExecutionHandler ¶ added in v0.6.0
type ExecutionHandler struct {
Client n8n.ClientInterface
}
ExecutionHandler handles execution history commands
type WorkflowChange ¶
type WorkflowChange struct {
NeedsUpdate bool
NeedsActivation bool
NeedsDeactivation bool
NeedsTagsUpdate bool
}
WorkflowChange represents possible changes between local and remote workflows
func DetectWorkflowChanges ¶
func DetectWorkflowChanges(local *n8n.Workflow, remote *n8n.Workflow) WorkflowChange
DetectWorkflowChanges compares local and remote workflows to detect what changes are needed
type WorkflowResult ¶ added in v0.5.0
type WorkflowResult struct {
WorkflowID string
Name string
FilePath string
Created bool
Updated bool
}
WorkflowResult contains the result of processing a workflow file
func CreateWorkflow ¶ added in v0.5.2
func CreateWorkflow(client n8n.ClientInterface, cmd *cobra.Command, workflow *n8n.Workflow, filename string, dryRun bool, result WorkflowResult) (WorkflowResult, error)
CreateWorkflow creates a new workflow without ID
func CreateWorkflowWithID ¶ added in v0.5.2
func CreateWorkflowWithID(client n8n.ClientInterface, cmd *cobra.Command, workflow *n8n.Workflow, filename string, dryRun bool, result WorkflowResult) (WorkflowResult, error)
CreateWorkflowWithID creates a new workflow with a specified ID
func ProcessWorkflowFile ¶
func ProcessWorkflowFile(client n8n.ClientInterface, cmd *cobra.Command, filePath string, dryRun bool, prune bool) (WorkflowResult, error)
ProcessWorkflowFile processes a workflow file and uploads it to n8n
func UpdateWorkflow ¶ added in v0.5.2
func UpdateWorkflow(client n8n.ClientInterface, cmd *cobra.Command, workflow *n8n.Workflow, filename string, dryRun bool, result WorkflowResult) (WorkflowResult, error)
UpdateWorkflow updates an existing workflow