Skip to content

Variable Capture

The @capture directive extracts values from responses and stores them as variables for use in subsequent requests.

@capture variableName = body.path.to.value
@name Login
POST {{baseUrl}}/auth/login
Content-Type: application/json
{
"email": "{{email}}",
"password": "{{password}}"
}
@capture token = body.access_token

After this request executes, {{token}} is available in any subsequent request.

By default, captured variables are stored in the session scope. You can specify a different scope with a prefix:

ScopeSyntaxPersistence
Session (default)@capture token = body.tokenCurrent session only
Collection@capture collection.token = body.tokenShared across the collection
Environment@capture env.token = body.tokenSaved to the active environment
Global@capture global.token = body.tokenAvailable everywhere
@name Login
POST {{baseUrl}}/auth/login
@capture token = body.access_token
@capture env.userId = body.user.id
@capture collection.refreshToken = body.refresh_token
@capture global.apiVersion = body.version

You can also capture literal values (strings, numbers, booleans):

@capture session.status = "active"
@capture session.count = 42
@capture session.flag = true

The path supports dot notation to traverse the response body:

{
"user": {
"id": 123,
"profile": {
"name": "John"
}
}
}
@capture userId = body.user.id
@capture userName = body.user.profile.name