简体   繁体   中英

How to get the next task in a REST API request using postman?

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

And I want to query task_id=102, but without putting 102 in the URL manually, but have something like this in the URL:

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?

change you url to:

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

now we are referring to id variable instead of hard coding it. now modify it from the pre-request script as: just add this to pre-request script

pm.environment.get("id") ? pm.environment.set("id",pm.environment.get("id")+1) : pm.environment.set("id",101)

//pm.environment.unset("id")

now for each request send the id will get incremented. if you want to reset it to 101 just send one request with pm.environment.unset("id") uncommented and then comment it back

You could use environment variables and fulfill those automatically when you get a response from the first request.

Take a look at this doc: https://blog.postman.com/extracting-data-from-responses-and-chaining-requests/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM