Extract Variables
Pre-request operations are performed before the request is sent, allowing for custom scripts and database connections. These are commonly used for setting input parameters, printing data, etc.
Post-response operations take place after a request is sent and are typically used for setting variables, performing assertions, and similar tasks. They also support custom scripts and database connections.
Extracting specific fields from an interface's response and setting them as variables can be done similarly to scripting.
pm.globals.set("key", "value");
pm.environment.set("key", "value");
Add Set Variables
Extract Variables from Response JSON
Extracting Variables from Response JSON: When the response is in JSON format, variables can be extracted quickly using JSONPath expressions.
- Supports adding multiple variables at once.
- Supports adding environment, temporary, and global variables.
JSON Path Extraction Tool
Extract Variables from Response XML
When the response is in XML format, variables can be quickly extracted from the result using XPath expressions.
- Supports adding multiple variables at once.
- Supports adding environment, temporary, and global variables.
In XPath, indexes start at 1, not 0. When extracting specific values, ensure to append text() at the end of your XPath expression.
XPath Extraction Tool
Extract Variables from Response Text
Extract values by filling in regular expressions and set them as variables.
Regular expressions must be enclosed in slashes (/).
Extract Variables from Response Header
Extract Variables from Response Cookie
Set Response Time as a Variable
Simply fill in the variable name to set the response time as a variable.