Bucket_id is always 0

I migrated recently from 0.21.0 to 0.24.2

While trying to work via api, I noticed that the field bucket_id is always 0:

Reproduce with:

curl -s -q -G "${URL}/projects/${LIST_ID}/tasks" -H "Content-type:application/json" -H "Authorization: Bearer ${TOKEN}" --data-urlencode "sort_by=created" --data-urlencode "order_by=desc" | jq -r ".[]"

Answer:

{
  "id": 2476,
  "title": "title",
  "description": "desc",
  "done": true,
  "done_at": "2024-02-20T12:07:56+01:00",
  "due_date": "0001-01-01T00:00:00Z",
  "reminders": null,
  "project_id": 3,
  "repeat_after": 0,
  "repeat_mode": 0,
  "priority": 0,
  "start_date": "2024-02-07T11:10:52+01:00",
  "end_date": "2024-02-20T12:07:56+01:00",
  "assignees": [
    {
      "id": 2,
      "name": "",
      "username": "my_user",
      "created": "2022-09-20T09:22:30+02:00",
      "updated": "2022-09-20T09:23:26+02:00"
    }
  ],
  "labels": null,
  "hex_color": "e0fff7",
  "percent_done": 0,
  "identifier": "#533",
  "index": 533,
  "related_tasks": {},
  "attachments": null,
  "cover_image_attachment_id": 0,
  "is_favorite": false,
  "created": "2024-02-07T11:10:52+01:00",
  "updated": "2024-08-27T15:51:45+02:00",
  "bucket_id": 0,
  "position": 0,
  "reactions": null,
  "created_by": {
    "id": 6,
    "name": "",
    "username": "my_user",
    "created": "2022-09-23T10:10:42+02:00",
    "updated": "2022-10-06T09:48:05+02:00"
  }
}

As a side note, position is also always 0, but I do not rely on that value.

Quoting from the docs:

Will only be populated when the task is accessed via a view with buckets. Can be used to move a task between buckets. In that case, the new bucket must be in the same view as the old one.

And similar for position:

The position of the task - any task project can be sorted as usual by this parameter. When accessing tasks via views with buckets, this is primarily used to sort them based on a range. Positions are always saved per view. They will automatically be set if you request the tasks through a view endpoint, otherwise they will always be 0. To update them, take a look at the Task Position endpoint.

That means when you access the task individually, both properties will always be empty. Only when you access all tasks through a view with buckets will the field contain the bucket id.

In understand…

Previously I got all tasks of a bucket by getting all tasks and selecting the with jq like select ( .bucket_id == (${BUCKET_ID})

What’s the actual way to get all tasks of a bucket? I didn’t find it on try.vikunja.io docs, but I suppose I have missed that :slight_smile:

You can still do that when you fetch all tasks for a view: Vikunja API documentation

Or better yet, combine it with a filter to only return tasks which are in the bucket you care about:

/api/v1/projects/1/views/4/tasks?sort_by[]=position&order_by[]=asc&filter=bucket_id+%3D+1