Using scripts to modify request messages
pm.request
to read or modify request messages.// pm.variables.replaceIn: handling variables in parameters
var body = pm.variables.replaceIn(pm.request.body.raw);
var jsonData = JSON.parse(body);
TIP
Variable Substitution
, which replaces all variables (including dynamic variables) in the request with the actual value.URL related information
Header parameters
Query parameters
Body parameters
pm.request.body
which is a RequestBody instance.TIP
var body = pm.request.body.toJSON();
console.log("body object", body);
var bodyStr = body.raw;
console.log("body string", bodyStr);
var bodyJSON = JSON.parse(bodyStr);
bodyJSON.id = 100;
pm.request.body.update(JSON.stringify(bodyJSON, null, 2));
console.log("Modified body", pm.request.body.toJSON());
1. Body Type: form-data
2. Body Type: x-www-form-urlencode
3. Body Type: JSON
4. Body Type: raw
Modified atΒ 2024-07-19 09:35:07