postman

Pass dynamic value to url in Postman


I have 2 requests

1st Request

After did my first request, I get the response where I can parse for a taskId

In my test tab, I will then parse and store it like this

let taskId = pm.response.json().body.result[0].data.task
console.log(taskId)

I can see taskId printing in my console as 938

2nd Request

I require making a GET with this dynamic URL with the taskId that I got from the first one

http://localhost:3000/fortinet/monitor/{{taskId}}

So I set the above URL , set the HTTP verb to GET

in my Pre-request Script tab, I did this

let taskId = pm.globals.get("taskId") 

Result

ReferenceError: taskId is not defined

Image Result

enter image description here

How can I debug this further?


Solution

  • You have to set variable, but you are doing it wrong.
    try this:
    pm.globals.set("taskID", pm.response.json().body.result[0].data.task)

    more you can read here: https://learning.postman.com/docs/postman/variables-and-environments/variables/