Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass dynamic value to url in Postman

Tags:

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?

like image 459
code-8 Avatar asked Dec 03 '22 20:12

code-8


1 Answers

The most suggested way is to use :key as in

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

See the colon before taskId. The reason being, URI values sometimes many not be environment dependent. So, based on the usecase, you can use like I said or {{taskId}}

like image 176
Naveen K Reddy Avatar answered Dec 06 '22 10:12

Naveen K Reddy