Postman-----Pass the parameter value in the response Body of the A request into the request body of the next request B as a parameter to send the request [1]

illustrate:

  Pass the parameter value in the response Body in the A request into the request body of the next request B, and send the request as a parameter [1] Mainly solve the transmission of a single parameter. If the parameters that need to be passed in the response body are multiple values, it will be introduced in [2].

Question: Pass the "id" of the response body in the A interface into the request body of the B interface.

Solution:

1. Set the environment variable in the test of the A interface .

  Code: var data = JSON.parse(responseBody) ;

       pm.environment.set("id", data.data.todo_list[0].id);    

    Explanation: pm.environment.set("id", data.data.todo_list[0].id), "id": represents the key value of the environment variable, " data.data.todo_list[0].id": represents The value to set.

    Note: The value of value can be written according to the structure returned by body.

 

2. Check whether the above steps set the id to the environment variable

 It can be seen that the value in the response body of interface A has been automatically set to the environment for interface B to use.

3. Write in the request body of the B interface

 The above is done.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324450731&siteId=291194637