From de4b673c278800ca8abe094cc6d98081f082cebe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 17 Nov 2025 13:22:46 +0000 Subject: [PATCH] Fix label addition by including labels in task creation payload - Include labels directly in task creation payload instead of adding separately - Format labels as array of objects with "id" field to match Vikunja API - Remove separate label addition step which was failing silently - Labels should now be created with the task in a single API call Co-authored-by: Mord0reK <135718526+Mord0reK@users.noreply.github.com> --- internal/glance/widget-vikunja.go | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/internal/glance/widget-vikunja.go b/internal/glance/widget-vikunja.go index 91b01b2..5dc48b0 100644 --- a/internal/glance/widget-vikunja.go +++ b/internal/glance/widget-vikunja.go @@ -394,6 +394,14 @@ func (widget *vikunjaWidget) createTask(title string, dueDate string, labelIDs [ // Use the configured project ID for creating tasks url := fmt.Sprintf("%s/api/v1/projects/%d/tasks", widget.URL, widget.ProjectID) + // Build labels array - Vikunja expects label objects with "id" field + labels := make([]map[string]interface{}, 0) + for _, labelID := range labelIDs { + labels = append(labels, map[string]interface{}{ + "id": labelID, + }) + } + // Build payload matching Vikunja API structure // Based on Vikunja API documentation and user-provided payload structure payload := map[string]interface{}{ @@ -401,7 +409,7 @@ func (widget *vikunjaWidget) createTask(title string, dueDate string, labelIDs [ "description": "", "done": false, "priority": 0, - "labels": []interface{}{}, // Empty array, labels will be added separately + "labels": labels, "project_id": widget.ProjectID, } @@ -430,23 +438,5 @@ func (widget *vikunjaWidget) createTask(title string, dueDate string, labelIDs [ return nil, err } - // Add labels to the task after creation - // Labels must be added separately via the labels endpoint - var labelErrors []error - for _, labelID := range labelIDs { - if err := widget.addLabelToTask(task.ID, labelID); err != nil { - labelErrors = append(labelErrors, fmt.Errorf("label %d: %w", labelID, err)) - } - } - - // If all labels failed to add, we still return the task but note the error - // The task was created successfully, just without labels - if len(labelErrors) > 0 && len(labelErrors) == len(labelIDs) { - // All labels failed - this might indicate a problem but task is still created - for _, lerr := range labelErrors { - fmt.Printf("Warning: %v\n", lerr) - } - } - return &task, nil }