Skip to main content

Extract Variables

tip

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

image.png

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.

  1. Supports adding multiple variables at once.
  2. Supports adding environment, temporary, and global variables.

image.png

JSON Path Extraction Tool

image.png

Extract Variables from Response XML

When the response is in XML format, variables can be quickly extracted from the result using XPath expressions.

  1. Supports adding multiple variables at once.
  2. Supports adding environment, temporary, and global variables.

image.png

caution

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 image.png

Extract Variables from Response Text

Extract values by filling in regular expressions and set them as variables.

caution

Regular expressions must be enclosed in slashes (/).

image.png

Extract Variables from Response Header

image.png

image.png

Set Response Time as a Variable

Simply fill in the variable name to set the response time as a variable.

image.png