Skip to main content

Resolve Parameter Dependencies, Data Passing Between Interfaces

Usage Scenario

B interface request parameters depend on the data returned by A interface. We hope that when B interface sends a request, it can get the data returned by A interface as request parameters.

Implementation Idea

Assign the data returned by interface A to a global variable or environment variable through a post-execution script.

Specific Example

We need the token parameter returned by the login interface for a news list. A common scenario is accessing an interface that requires login to view.

1. Prepare the interfaces

For demonstration purposes, we first prepare two interfaces:

get_token interface:

Request URL: {{url}}/api/demo/login

It will return a token parameter. As shown in the figure:

image.png

News list interface:

Request URL: {{url}}/demo/news_list?mobile=****&theme_news=International News&page=1&pageSize=20

It requires the token parameter returned by the login interface as its request parameter.

image.png As shown in the figure above, we defined an environment variable token. Since it has not been bound to the token returned by the login interface, it is output as is.

2. Bind the response result to the variable

At this point, click the [Post-execution Operation - Custom Script] of the login interface, and assign the login response result token to the environment variable token through a variable assignment.

image.png At this point, click the [Send] button to bind the token returned by the login interface to the environment variable token.

We enter the news list interface and click send, and you will see that the token is the token we just obtained.

image.png Note: After binding, we need to send the login interface request again (execute the binding data) before requesting the news list interface.

Appendix: Response Data Variables

response.raw: Original response data

Call example:
response.raw.status // Response status code (200, 301, 404, etc.)
response.raw.responseTime // Response time (milliseconds)
response.raw.type // Response type (json, etc.)
response.raw.responseText // Response text

response.json: JSON format response data

image.png

Call example as shown above:

response.json.data.token // or response.json.data["token"]

response.headers: Response headers

image.png

Call example:

response.headers.server // or response.headers["server"]

response.cookies: Response cookies

Call example:

response.cookies.PHPSESSION // or response.cookies["PHPSESSION"]