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>
pull/878/head
copilot-swe-agent[bot] 2025-11-17 13:22:46 +07:00
parent ef3e7f73f3
commit de4b673c27
1 changed files with 9 additions and 19 deletions

@ -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
}