Chain requests with variables
A common pattern is to log in, capture a token from the response, and use it on the next request. You
do this with a post-response script that writes an environment variable, then a {{variable}}
placeholder on the following request.
1. Capture the value
Section titled “1. Capture the value”On the login request, add a post-response script that reads the response and stores what you need:
const body = fp.response.json();fp.environment.set('token', body.accessToken);fp.environment.set('userId', body.user.id);fp.environment.set persists the value after the send, so later requests see it.
2. Use it on the next request
Section titled “2. Use it on the next request”Reference the captured value with a placeholder anywhere interpolation applies — URL, headers, body:
GET {{baseUrl}}/api/users/{{userId}}Authorization: Bearer {{token}}Same-send scratch values
Section titled “Same-send scratch values”If you only need a value within a single send (for example, to pass data from the pre-request to the post-response script of the same request), use the ephemeral scratch space instead of polluting the environment:
// pre-requestfp.variables.set('startedAt', Date.now());// post-responseconst elapsed = Date.now() - fp.variables.get('startedAt');fp.log(`round trip: ${elapsed} ms`);fp.variables.* is discarded when the send completes. See Variables and
Variable precedence for how names resolve.