Get the next task id from the URL

My question:
I use this POST request to create two process instances with id 101 and 102:

POST http://localhost:8080/kie-server/services/rest/server/containers/test_1.0.0-SNAPSHOT/processes/test.test1/instances/correlation/test_1

Lets say I have a REST API get request like this one that query the task_id=101:

GET  http://localhost:8080/kie-server/services/rest/server/queries/tasks/instances/process/101

This query will get me an output like this one:

{ "task-summary" : [ ]}

The output that I want to get is in the process instance id 102 and it looks like this one:

"task-summary" : [ {
    "task-id" : 60,
    "task-name" : "Testing_env",
    "task-subject" : "",
    "task-description" : "Testing",
    "task-status" : "Ready",
    "task-priority" : 0,
    "task-is-skipable" : false,
    "task-actual-owner" : null,
    "task-created-by" : null,
    "task-created-on" : {
  "java.util.Date" : 1622841074000

So, how can i somehow get the request for only id 102 with an url like this:

GET  http://localhost:8080/kie-server/services/rest/server/queries/tasks/instances/process/101+1

I tried this and it wont work. So, what I actually want is to add somehow that +1 not to put 102 manually there?

Hey @technical-administr2 :wave: Welcome to the Postman Community :tada:

Thanks for reaching out! If I understand your query correctly, you want to modify the path parameter without directly entering the value (102), is that correct?

In that case, maybe you can add a script like this in the pre-request script?

let task_id = 101
let useDefault = false // or true for 101
if (!useDefault) {
    task_id = 102
pm.environment.set('task_id', task_id)

Then replace the request URL with following:

GET  http://localhost:8080/kie-server/services/rest/server/queries/tasks/instances/process/{{task_id}}

Hope this helps, but please do let me know if this is not exactly what you want to achieve :slightly_smiling_face:

Thanks a lot @taehoshino, it worked!

1 Like