How do I acquire the taskId for a particular processInstanceId in Camunda Platform 8?

Using TaskList(Graphql) API,

I was able to extract task information using the snippet below.

query GetTask($id: String!) {
  task(id: $id) {
    id
    variables
    taskDefinitionId
    formKey
    processDefinitionId
    assignee
    name
    taskState
    processName
    creationTime
    completionTime
    __typename
  }
}

However, using process Instance Id, I’m unable to obtain the task id.

Is it possible to get the task id from the given process instance id? using camunda platform 8.

Greetings, Camunda Platform 8 Team!

I’d like your opinion on the aforementioned Usecase.?

Regards, Thank you,

Hi Ramakrishnan,

One option might be to store a unique custom business key as a process variable. For example, you could set a variable my-business-key with value xyz.

Then, it’s possible to use the operate rest api to find variables. For example, you could find the variables for instance id 123 like this:

POST <operate-url>/api/process-instances/123/variables

(with payload of {“scopeId”:“123"})

… the result would look something like …

[
    {
        "id": "123-my-business-key",
        "name": "My Business Key",
        "value": "\"xyz\"",
        "isPreview": false,
        "hasActiveOperation": false,
        "isFirst": true,
    }
]

Now that you have the value of my-business-key, search for all tasks with something like this (via tasklist graphql api):

{
  tasks(query: {taskDefinitionId: "my_user_task"}) {
    id
    name
    taskDefinitionId
    variables {
        id
        name
        value
    }
  }
}

And then filter the results to find the task with the variable named my-business-key and value xyz

{
    "data": {
        "tasks": [
            {
                "name": "My User Task",
                "id": "2251799813685261",
                "taskDefinitionId": "my_user_task",
                "variables": [
                    {
                        "id": "123-my-business-key",
                        "name": "My Business Key",
                        "value": "\"xyz\""
                    }
                ]
            }
        ]
    }
}

I’ll reply to this thread if I find a better way, but that’s the best I can find for now. Hope that helps!