Vikunja API Create Task 404 error

Hey Fellas,

I’m trying to create a task from python through the API but I get 404 error.
Authentication is working and I can also query the tasks, but when I try to create one I get <Response [404]> {"message":"Not Found"}.

        print(requests.get(url=f"{self.url}/api/v1/projects/17/tasks", headers={"Authorization": f"Bearer {self.__token}"}).text)
        task2 = {"project_id": 17, "title": "Test"}
        task = {
                  "assignees": [],
                  "attachments": [],
                  "bucket_id": 30,
                  "cover_image_attachment_id": None,
                  "created": "1970-01-01T00:00:00.000Z",
                  "created_by": {
                    "created": None,
                    "email": "",
                    "exp": 0,
                    "id": 0,
                    "name": "",
                    "type": 0,
                    "updated": None,
                    "username": ""
                  },
                  "description": "",
                  "done": False,
                  "done_at": None,
                  "due_date": None,
                  "end_date": None,
                  "hex_color": "",
                  "id": 0,
                  "identifier": "",
                  "index": 0,
                  "is_favorite": False,
                  "kanban_position": 0,
                  "labels": [],
                  "max_right": None,
                  "parent_task_id": 0,
                  "percent_done": 0,
                  "position": 0,
                  "priority": 0,
                  "project_id": 17,
                  "related_tasks": {},
                  "reminder_dates": None,
                  "reminders": [],
                  "repeat_after": 0,
                  "repeat_from_current_date": False,
                  "repeat_mode": 0,
                  "start_date": None,
                  "subscription": None,
                  "title": "Test",
                  "updated": "1970-01-01T00:00:00.000Z"
                }
        res = requests.post(url=f"{self.url}/api/v1/projects/{prj_id}/tasks",
                            headers={"Content-Type": "application/json", "Authorization": f"Bearer {self.__token}"},
                            json=task)
POST 200 /api/v1/login 176.48712ms - python-requests/2.31.0
GET 200 /api/v1/projects/17/tasks 6.942443ms - python-requests/2.31.0
POST 404 /api/v1/projects/17/tasks 135.719µs - python-requests/2.31.0

I also tried with vja but it’s the same result.

Frontend Version: 0.21.0+322-218d72494a
API Version: v0.21.0+189-66afe52afb

Can you reproduce this on try?

Yes it’s the same. Query works but trying to create a task results in 404 error.

        print(requests.get(url=f"{self.url}/api/v1/info", headers={"Authorization": f"Bearer {self.__token}"}).text)
        print(requests.get(url=f"{self.url}/api/v1/projects/{prj_id}/tasks", headers={"Authorization": f"Bearer {self.__token}"}).text)
        task = {
                  "assignees": [],
                  "attachments": [],
                  "bucket_id": 30,
                  "cover_image_attachment_id": None,
                  "created": "1970-01-01T00:00:00.000Z",
                  "created_by": {
                    "created": None,
                    "email": "",
                    "id": 0,
                    "name": "",
                    "updated": None,
                    "username": ""
                  },
                  "description": "",
                  "done": False,
                  "done_at": "",
                  "due_date": "",
                  "end_date": "",
                  "hex_color": "",
                  "id": 0,
                  "identifier": "",
                  "index": 0,
                  "is_favorite": False,
                  "kanban_position": 0,
                  "labels": [],
                  "percent_done": 0,
                  "position": 0,
                  "priority": 0,
                  "project_id": prj_id,
                  "related_tasks": {},
                  "reminders": [],
                  "repeat_after": 0,
                  "repeat_mode": 0,
                  "start_date": "",
                  "subscription": None,
                  "title": "Test",
                  "updated": "1970-01-01T00:00:00.000Z"
                }
        res = requests.post(url=f"{self.url}/api/v1/projects/{prj_id}/tasks",
                            headers={"Content-Type": "application/json", "Authorization": f"Bearer {self.__token}"},
                            json=task)
        print(res, res.text)

output:

{"version":"v0.21.0+189-66afe52afb","frontend_url":"https://try.vikunja.io/","motd":"You can use the user 'demo' and password 'demo' to login. This is a demo instance only and will be reset at irregular intervals. Do not use this for real data.","link_sharing_enabled":true,"max_file_size":"20MB","registration_enabled":true,"available_migrators":["vikunja-file","ticktick","todoist"],"task_attachments_enabled":true,"enabled_background_providers":["upload","unsplash"],"totp_enabled":false,"legal":{"imprint_url":"","privacy_policy_url":""},"caldav_enabled":true,"auth":{"local":{"enabled":true},"openid_connect":{"enabled":false,"redirect_url":"https://try.vikunja.io/auth/openid/","providers":null}},"email_reminders_enabled":true,"user_deletion_enabled":true,"task_comments_enabled":true,"demo_mode_enabled":false,"webhooks_enabled":true}

[{"id":1,"title":"This is a task","description":"","done":false,"done_at":"0001-01-01T00:00:00Z","due_date":"2023-11-06T15:00:00+01:00","reminders":null,"project_id":1,"repeat_after":0,"repeat_mode":0,"priority":0,"start_date":"2023-11-03T23:00:00+01:00","end_date":"2023-11-10T22:59:00+01:00","assignees":null,"labels":[{"id":1,"title":"label","description":"","hex_color":"e8e8e8","created_by":{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"},"created":"2021-05-30T10:45:46+02:00","updated":"2021-05-30T10:45:46+02:00"}],"hex_color":"","percent_done":0,"identifier":"#1","index":1,"related_tasks":{},"attachments":null,"cover_image_attachment_id":0,"is_favorite":false,"created":"2021-05-30T10:45:46+02:00","updated":"2023-11-04T15:15:38+01:00","bucket_id":1,"position":4294967296,"kanban_position":4294967296,"created_by":{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"}},{"id":2,"title":"And another one","description":"","done":false,"done_at":"0001-01-01T00:00:00Z","due_date":"0001-01-01T00:00:00Z","reminders":null,"project_id":1,"repeat_after":0,"repeat_mode":0,"priority":0,"start_date":"0001-01-01T00:00:00Z","end_date":"0001-01-01T00:00:00Z","assignees":null,"labels":null,"hex_color":"","percent_done":0,"identifier":"#2","index":2,"related_tasks":{},"attachments":null,"cover_image_attachment_id":0,"is_favorite":false,"created":"2021-05-30T10:45:53+02:00","updated":"2023-11-04T11:03:26+01:00","bucket_id":1,"position":3435973836.8,"kanban_position":3435973836.8,"created_by":{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"}},{"id":10,"title":"hi","description":"","done":false,"done_at":"0001-01-01T00:00:00Z","due_date":"0001-01-01T00:00:00Z","reminders":null,"project_id":1,"repeat_after":0,"repeat_mode":0,"priority":0,"start_date":"0001-01-01T00:00:00Z","end_date":"0001-01-01T00:00:00Z","assignees":null,"labels":null,"hex_color":"","percent_done":0,"identifier":"#3","index":3,"related_tasks":{},"attachments":null,"cover_image_attachment_id":0,"is_favorite":false,"created":"2023-11-04T08:05:45+01:00","updated":"2023-11-04T14:51:41+01:00","bucket_id":1,"position":2576980377.6000004,"kanban_position":2576980377.6000004,"created_by":{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"}},{"id":15,"title":"buy chocolate","description":"","done":false,"done_at":"0001-01-01T00:00:00Z","due_date":"0001-01-01T00:00:00Z","reminders":null,"project_id":1,"repeat_after":0,"repeat_mode":0,"priority":0,"start_date":"0001-01-01T00:00:00Z","end_date":"0001-01-01T00:00:00Z","assignees":null,"labels":null,"hex_color":"","percent_done":0,"identifier":"#4","index":4,"related_tasks":{},"attachments":null,"cover_image_attachment_id":0,"is_favorite":false,"created":"2023-11-04T14:54:59+01:00","updated":"2023-11-04T15:15:56+01:00","bucket_id":8,"position":1717986918.4,"kanban_position":4294967296,"created_by":{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"}},{"id":17,"title":"another one bites the dust","description":"","done":false,"done_at":"0001-01-01T00:00:00Z","due_date":"2023-11-06T14:59:01+01:00","reminders":null,"project_id":1,"repeat_after":0,"repeat_mode":0,"priority":0,"start_date":"0001-01-01T00:00:00Z","end_date":"0001-01-01T00:00:00Z","assignees":null,"labels":[{"id":11,"title":"dust","description":"","hex_color":"fd8a09","created_by":{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"},"created":"2023-11-04T14:59:16+01:00","updated":"2023-11-04T14:59:16+01:00"}],"hex_color":"","percent_done":0,"identifier":"#5","index":5,"related_tasks":{},"attachments":null,"cover_image_attachment_id":0,"is_favorite":false,"created":"2023-11-04T14:59:16+01:00","updated":"2023-11-04T15:10:16+01:00","bucket_id":1,"position":858993459.2,"kanban_position":858993459.2,"created_by":{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"}},{"id":22,"title":"Test task","description":"","done":false,"done_at":"0001-01-01T00:00:00Z","due_date":"0001-01-01T00:00:00Z","reminders":null,"project_id":1,"repeat_after":0,"repeat_mode":0,"priority":0,"start_date":"0001-01-01T00:00:00Z","end_date":"0001-01-01T00:00:00Z","assignees":[{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"}],"labels":null,"hex_color":"","percent_done":0,"identifier":"#6","index":6,"related_tasks":{},"attachments":null,"cover_image_attachment_id":0,"is_favorite":false,"created":"2023-11-04T15:42:58+01:00","updated":"2023-11-04T15:43:23+01:00","bucket_id":1,"position":429496729.6,"kanban_position":393216,"created_by":{"id":1,"name":"sergey","username":"demo","created":"2021-05-30T10:45:25+02:00","updated":"2023-11-04T13:25:16+01:00"}}]

<Response [404]> {"message":"Not Found"}

You need to use PUT instead of POST. Check out the docs: Vikunja API documentation

It does work work with PUT. Sorry I don’t know how I missed that. :sweat_smile: