Unable to create task linked to user story

Greetings! I am having issues creating a task linked to a user story via the Taiga API.

My Code
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + auth_request["auth_token"],

json_data = {
    'project': 1,
    'user_story': 324,
    'subject': 'Test'  

response = requests.post('http://my.url:9000/api/v1/tasks', headers=headers, json=json_data)

Here is the issue the error I am receiving:

{'user_story': ["Invalid pk '324' - object does not exist."]}

What I am guessing this means is that it is unable to find the according user story. This confuses me because there is a user story with that id on project 1. I cannot figure out why this is happening.

I have already tried listing out all user stories on that project but I did not find the user story I was looking for.

I does work if I leave out that the user story parameter.

Any help is much appreciated!

Hi @Komarovo

One user story have two identifiers, the id (or pk) and the ref:

  • ref is the value that every user see in the Taiga interface. The ref is a value that is generated from a sequence for each project. It starts at 1, is incremental and is shared by all elements (user stories, tasks, issues and epics) of a project. If #1 is from an issue, there will be no other object that uses that value in that project. This value is not a valid identifier in the taiga api.

  • id (or pk): Is a global identifier of an element, generated from a sequence unique to that type of element within the entire Taiga domain. It is the identifier used in the api.

So you have to use ids instead of refs in your calls.

I hope this can help.

That worked. Big thanks!

I guess I just did not do enough research.

I am still confused why the user story did not show up when listing all of the project. Works now, so does not matter.

1 Like

Your are welcome

Remember that API list endpoints are paginated so you only show the first ¿100? stories. You can show the documentation about API pagination here: Taiga REST API