Help Needed: "Invalid Token" Error When Creating Task via API

Howdy everyone,

I’m experiencing an issue with POST Method for creating tasks using the Vikunja API. Despite following the documentation, I’m consistently receiving the error:

{"message":"missing, malformed, expired or otherwise invalid token provided"}

Here’s what I’ve tried so far:

  1. API Endpoint:
  • URL: http://synology.*************.com:3456/api/v1/projects/1/tasks
  • Method: POST
  1. Request Headers:
  • Authorization: Bearer tk_75454cb3*************************************
  • Content-Type: application/json
  1. Request Body:
{
  "title": "Neue Aufgabe",
  "description": "Beschreibung der neuen Aufgabe"
}
  1. Steps Taken:
  • Verified that the API token is valid and correctly formatted.
  • Tested the request using curl with various configurations.
  • Tried with different tokens and endpoint configurations.

Command Line Input and Output:

root@b5dd7b*******:/# curl -X POST http://synology.***************.com:3456/api/v1/projects/1/tasks \
-H "Authorization: Bearer tk_75454cb33****************" \
-H "Content-Type: application/json" \
-d '{
  "title": "Neue Aufgabe",
  "description": "Beschreibung der neuen Aufgabe",
}'

{"message":"missing, malformed, expired or otherwise invalid token provided"}

Method GET instead of POST works
If u use the GET method everything works fine in the CLI and i get the output.

root@b5dd*******:/# curl -X GET http://synology.*************.com:3456/api/v1/projects/1/tasks \
-H "Authorization: Bearer tk_75454cb33********************"
[{"id":14,"title":"task1test","description":"\u003cp\u003e\u003c/p\u003e","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":"#1","index":1,"related_tasks":{},"attachments":null,"cover_image_attachment_id":0,"is_favorite":false,"created":"2024-08-11T21:12:53+02:00","updated":"2024-08-14T18:37:29+02:00","bucket_id":0,"position":0,"reactions":null,"created_by":{"id":1,"name":"**************","username":"********","created":"2024-08-09T11:53:24+02:00","updated":"2024-08-09T14:31:55+02:00"}}]

Questions:

  • Is there something specific I might be missing in the request or headers?
  • Could there be any additional configuration required on the server side?
  • Are there any known issues or additional steps to ensure the token is correctly processed by the API?

Any guidance or suggestions would be greatly appreciated. Thank you!

based off the endpoint you are utilizing here it looks like you are trying to add a task to a specific project. based off the docs you should be using PUT, so just change:

root@b5dd7b*******:/# curl -X POST http://synology.***************.com:3456/api/v1/projects/1/tasks \
-H "Authorization: Bearer tk_75454cb33****************" \
-H "Content-Type: application/json" \
-d '{
  "title": "Neue Aufgabe",
  "description": "Beschreibung der neuen Aufgabe",
}'

to

root@b5dd7b*******:/# curl -X PUT http://synology.***************.com:3456/api/v1/projects/1/tasks \
-H "Authorization: Bearer tk_75454cb33****************" \
-H "Content-Type: application/json" \
-d '{
  "title": "Neue Aufgabe",
  "description": "Beschreibung der neuen Aufgabe",
}'

and this should work

1 Like