Hey @vivek5080-05
Welcome to the Postman Community!
In your first request, it’s using pm.variables.set()
which only lives for the duration of that single request. It’s not storing those values in a variable anywhere.
The pm.variables.get()
in your second request would go pick the variable with that name, which is in the narrowest scope and use that - It wouldn’t be using anything from the first request.
I would personally just stick to using collectionVariables
for it all, that way you’re not getting tripped up by the way that pm.variables.get()
works in Postman.
This is from a slightly different context but uses the .shift()
method in the script that @michaelderekjones shared, It might be worth taking a look at.