terraform-provider-n8n

n8n

import "github.com/arthurbdiniz/terraform-provider-n8n/internal/pkg/n8n-client-go"

Package n8n-client-go provides Go client functionalities and data structures for interacting with the n8n automation platform.

It includes representations for workflows, nodes, tags, connections, and related metadata, enabling the management of automation tasks.

The package also includes an HTTP client to facilitate communication with the n8n service, allowing users to handle workflows, nodes, and other platform features.

Index

type Client

Client represents a client for the n8n service.

type Client struct {
    HostURL    string
    HTTPClient *http.Client
    Token      string
}

func NewClient

func NewClient(host *string, token *string) (*Client, error)

NewClient creates a new n8n client. It accepts a base URL and an API key for authentication.

Example:

client := n8n.NewClient("https://example.n8n.io", "your-api-key")

func (*Client) ActivateWorkflow

func (c *Client) ActivateWorkflow(workflowID string) (*Workflow, error)

ActivateWorkflow activates a workflow by its ID. This is typically used to enable workflow execution after creation or deactivation.

Parameters:

Returns the updated Workflow object, or an error if the request or decoding fails.

func (*Client) CreateWorkflow

func (c *Client) CreateWorkflow(createWorkflowRequest *CreateWorkflowRequest) (*Workflow, error)

CreateWorkflow sends a request to create a new workflow in n8n. It accepts a CreateWorkflowRequest object and returns the created Workflow with its assigned ID and metadata.

Parameters:

Returns the created Workflow object or an error if the request or decoding fails.

func (*Client) DeactivateWorkflow

func (c *Client) DeactivateWorkflow(workflowID string) (*Workflow, error)

DeactivateWorkflow deactivates a workflow by its ID. This is typically used to temporarily disable workflow execution.

Parameters:

Returns the updated Workflow object, or an error if the request or decoding fails.

func (*Client) DeleteWorkflow

func (c *Client) DeleteWorkflow(workflowID string) (*Workflow, error)

DeleteWorkflow deletes a workflow from your n8n instance by its ID.

Parameters:

Returns the deleted Workflow object, or an error if the request or decoding fails.

func (*Client) GetWorkflow

func (c *Client) GetWorkflow(workflowID string) (*Workflow, error)

GetWorkflow retrieves the details of a single workflow by its ID.

Parameters:

Returns a pointer to the Workflow struct, or an error if the request or decoding fails.

func (*Client) GetWorkflows

func (c *Client) GetWorkflows() (*WorkflowsResponse, error)

GetWorkflows retrieves all workflows from your n8n instance. This method supports pagination and will automatically iterate through all available pages by following the cursor in the response.

Returns a pointer to a WorkflowsResponse containing all workflows, or an error if the request or response decoding fails.

func (*Client) UpdateWorkflow

func (c *Client) UpdateWorkflow(id string, updateWorkflowRequest *UpdateWorkflowRequest) (*Workflow, error)

UpdateWorkflow sends a request to update an existing workflow in n8n. It accepts the workflow ID and an UpdateWorkflowRequest object, then returns the updated Workflow with its assigned ID and metadata.

Parameters:

Returns the updated Workflow object or an error if the request or decoding fails.

type Connection

Connection represents the connections from a node to other nodes within a workflow.

type Connection struct {
    // Main holds the raw connection data. It should be further structured for improved type safety.
    // TODO: Find a way to transform this into a concrete struct.
    Main json.RawMessage `json:"main"`
}

type ConnectionDetail

ConnectionDetail provides detailed information about a specific connection between nodes.

type ConnectionDetail struct {
    // Node is the identifier of the target node in the connection.
    Node string `json:"node"`

    // Type describes the type of connection (e.g., main, conditional).
    Type string `json:"type"`

    // Index is the positional index of the connection in a list.
    Index int `json:"index"`
}

type CreateWorkflowRequest

CreateWorkflowRequest defines the allowed fields when creating a workflow.

type CreateWorkflowRequest struct {
    Name        string                `json:"name"`
    Nodes       []Node                `json:"nodes"`
    Connections map[string]Connection `json:"connections"`
    Settings    Settings              `json:"settings"`
}

type Node

Node represents an individual step in a workflow, including its configuration and metadata.

type Node struct {
    // Parameters is a map containing node-specific configuration options.
    Parameters map[string]interface{} `json:"parameters"`

    // Type defines the type of the node (e.g., HTTP Request, Set, Code).
    Type string `json:"type"`

    // TypeVersion indicates the version of the node type.
    TypeVersion float64 `json:"typeVersion"`

    // Position is the visual location of the node on the workflow canvas.
    Position []int `json:"position"`

    // ID is the unique identifier of the node.
    ID  string `json:"id"`

    // Name is the user-defined name of the node.
    Name string `json:"name"`
}

type Settings

Settings contains global execution settings for a workflow.

type Settings struct {
    SaveExecutionProgress    bool   `json:"saveExecutionProgress"`
    SaveManualExecutions     bool   `json:"saveManualExecutions"`
    SaveDataErrorExecution   string `json:"saveDataErrorExecution"`   // Enum: "all", "none"
    SaveDataSuccessExecution string `json:"saveDataSuccessExecution"` // Enum: "all", "none"
    ExecutionTimeout         int    `json:"executionTimeout"`         // maxLength: 3600
    ErrorWorkflow            string `json:"errorWorkflow"`
    Timezone                 string `json:"timezone"`
    ExecutionOrder           string `json:"executionOrder"`
}

type Tag

Tag represents a label assigned to a workflow for organizational purposes.

type Tag struct {
    // CreatedAt is the timestamp when the tag was created.
    CreatedAt string `json:"createdAt"`

    // UpdatedAt is the timestamp when the tag was last updated.
    UpdatedAt string `json:"updatedAt"`

    // ID is the unique identifier of the tag.
    ID  string `json:"id"`

    // Name is the name of the tag.
    Name string `json:"name"`
}

type UpdateWorkflowRequest

UpdateWorkflowRequest defines the allowed fields when updating a workflow.

type UpdateWorkflowRequest struct {
    Name        string                `json:"name"`
    Nodes       []Node                `json:"nodes"`
    Connections map[string]Connection `json:"connections"`
    Settings    Settings              `json:"settings"`
}

type Workflow

Workflow represents a workflow in n8n, including metadata, configuration, nodes, connections, and tags.

type Workflow struct {
    // ID is the unique identifier of the workflow.
    ID  string `json:"id"`

    // Name is the human-readable name of the workflow.
    Name string `json:"name"`

    // Active indicates whether the workflow is currently active.
    Active bool `json:"active"`

    // VersionId is the identifier for the specific version of the workflow.
    VersionId string `json:"versionId"`

    // TriggerCount tracks the number of times the workflow has been triggered.
    TriggerCount int `json:"triggerCount"`

    // CreatedAt is the timestamp when the workflow was created.
    CreatedAt string `json:"createdAt"`

    // UpdatedAt is the timestamp when the workflow was last updated.
    UpdatedAt string `json:"updatedAt"`

    // Nodes is a list of nodes that define the steps within the workflow.
    Nodes []Node `json:"nodes"`

    // Connections maps node names to their connections, defining how nodes
    // are connected in the workflow.
    Connections map[string]Connection `json:"connections"`

    // Settings contains configuration options for workflow execution.
    Settings Settings `json:"settings"`

    // Tags is a list of tags associated with the workflow for categorization.
    Tags []Tag `json:"tags"`
}

type WorkflowsResponse

WorkflowsResponse represents a paginated response from an API call that returns a list of workflows.

type WorkflowsResponse struct {
    // Data contains the list of workflows returned in the response.
    Data []Workflow `json:"data"`

    // NextCursor is an optional cursor string used for pagination.
    // If there are more results to fetch, this field will contain the cursor
    // for the next page. It is nil when there are no additional pages.
    NextCursor *string `json:"nextCursor"`
}

Generated by gomarkdoc