Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access path parameters with postman's test?

Tags:

postman

I need to use a path param and it seems works

Request1 .../:token/some

Now how can I reuse the value provided for :token in Request1 in other request? So that I don't need put same values on every request?

Request2 .../:token/other

How can I store the value of :token in Request1's test codes? I know how to put a value to the environment

pm.environment.set("", "");

I want to know how to access the value of :token path segment.

like image 552
Jin Kwon Avatar asked Oct 27 '25 21:10

Jin Kwon


1 Answers

I found an answer.

Try to print out the pm.request.url which is an array.

Now we can access the path segment with an index.

var token = pm.request.url.path[2];
pm.environment.set("token", token);
like image 172
Jin Kwon Avatar answered Oct 30 '25 17:10

Jin Kwon