Skip to main content

Variables Extraction

"Post-operation" supports adding the Extract Variable function, which can automatically extract data based on the results returned by the API and set it as a variable (temporary variable/environment variable/global variable), which is convenient for other APIs to use directly.

Set up Assertions

Open an API in Apidog, and clicking the Extract Variable in Post Processors.

How to transfer data between interfaces

Testers often encounter a situation where B request parameters depend on A the returned data.

Now assume that during an automated test process, the value in A the returned data needs to be extracted as the request parameter. The following will demonstrate how to complete the parameter transfer and connection between two interfaces.

Implementation

1. A interface adds post-operation to extract

Add the "environment variable" in the post-operation of the A interface , and define the variable name categoryId and JSONPath expression in it . If you want to extract the parameters data in the structure of the returned data categoryId, you should fill in the JSONPath expression $.data.category.id.

adada

You can see the new extracted values ​​in the console after sending the interface request.

2. B : Directly reference the variables set above in the corresponding parameter values.

By directly filling in the request parameters in interface B {{categoryId}}, you can directly reference the value returned by interface A in the request parameters.

adada

You can see the new extracted values ​​in the console after sending the interface request.

If you are not sure whether the data generated by interface A is correctly referenced, you can add the following custom script in the pre-operation of interface B:

var petid = pm.environment.get("petid");

console.log(petid)

adada

This allows you to view the referenced variable values ​​in the console.