Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"time"
)

const defaultListPageSize = 250

// Client is the n8n API client
type Client struct {
baseURL string
Expand Down Expand Up @@ -170,8 +172,8 @@ func (c *Client) request(method, path string, body interface{}) ([]byte, error)
return respBody, nil
}

// ListWorkflows returns all workflows
func (c *Client) ListWorkflows(opts ListWorkflowsOptions) (*ListResult[Workflow], error) {
// listWorkflowsPage fetches a single page of workflows.
func (c *Client) listWorkflowsPage(opts ListWorkflowsOptions) (*ListResult[Workflow], error) {
params := url.Values{}
if opts.Limit > 0 {
params.Set("limit", strconv.Itoa(opts.Limit))
Expand Down Expand Up @@ -213,6 +215,39 @@ func (c *Client) ListWorkflows(opts ListWorkflowsOptions) (*ListResult[Workflow]
return &resp, nil
}

// ListWorkflows returns all workflows, auto-paginating through all pages.
// If opts.Cursor is set, only that single page is returned (manual pagination).
func (c *Client) ListWorkflows(opts ListWorkflowsOptions) (*ListResult[Workflow], error) {
// Manual pagination: caller provided a cursor, return single page
if opts.Cursor != "" {
return c.listWorkflowsPage(opts)
}

pageSize := opts.Limit
if pageSize <= 0 {
pageSize = defaultListPageSize
}

var all []Workflow
pageOpts := opts
pageOpts.Limit = pageSize

for {
page, err := c.listWorkflowsPage(pageOpts)
if err != nil {
return nil, err
}
all = append(all, page.Data...)

if page.NextCursor == "" || len(page.Data) == 0 {
break
}
pageOpts.Cursor = page.NextCursor
}

return &ListResult[Workflow]{Data: all}, nil
}
Comment on lines +220 to +249

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This new implementation of ListWorkflows changes the behavior of the --limit flag in a breaking way. Previously, it limited the total number of results. Now, it controls the page size for auto-pagination, and there is no longer a way to limit the total number of returned workflows. This can be surprising to users and may cause performance issues if they unintentionally fetch a very large number of workflows.

Consider re-introducing a way to limit the total number of results, perhaps by making --limit a total limit again and adding a new --page-size flag for when pagination is desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the intentional behavior change — the whole point of this PR. The old --limit 100 default silently hid 210 of 310 workflows on prod. Nobody was using --limit to deliberately cap results; it was just a page size that happened to truncate output.

This is an internal CLI (n8nctl), so there's no external compatibility concern. Adding a separate --page-size flag would be YAGNI.


// GetWorkflow returns a workflow by ID
func (c *Client) GetWorkflow(id string) (*Workflow, error) {
respBody, err := c.request(http.MethodGet, "/workflows/"+url.PathEscape(id), nil)
Expand Down
8 changes: 2 additions & 6 deletions internal/cmd/workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,15 @@ func newListCmd() *cobra.Command {
fmt.Printf("%-18s %-6s %s\n", wf.ID, activeStr, wf.Name)
}

if result.NextCursor != "" {
fmt.Printf("\nMore results available. Use --cursor %s to continue.\n", result.NextCursor)
}

return nil
},
}

cmd.Flags().BoolVar(&active, "active", false, "Show only active workflows")
cmd.Flags().BoolVar(&inactive, "inactive", false, "Show only inactive workflows")
cmd.Flags().StringSliceVar(&tags, "tag", nil, "Filter by tag (can be repeated)")
cmd.Flags().IntVar(&limit, "limit", 100, "Maximum number of workflows to return")
cmd.Flags().StringVar(&cursor, "cursor", "", "Pagination cursor for next page")
cmd.Flags().IntVar(&limit, "limit", 0, "Page size per API request (0 = default)")
cmd.Flags().StringVar(&cursor, "cursor", "", "Pagination cursor (fetches single page only)")
cmd.Flags().StringVar(&projectID, "project", "", "Filter by project ID")
cmd.Flags().StringVar(&name, "name", "", "Filter by workflow name")

Expand Down
Loading