如何发送带有参数的邮递员获取请求作为另一个请求的响应数组

How to send a postman Get-Request with params as response-array of another request

我正在尝试使用 Postman 发送 2 个 Get-Requests,其中响应 1 用于请求 2,如下所示:

    {   "userId": 1,
        "id": 6,
        "title": "dolorem eum magni eos aperiam quia",
        "body": "ut aspernatur ... "
    },
    {
     ... 

有很多。所以我有很多 userId 从 1 到 10。

现在我想使用 Postman 中的参数将 Response_1 的所有 userId 放入 Request_2:

我怎样才能把 Response_1 中的所有 userIdKey : Value 这样的一对 Request_2 一起放到 Request_2 中。非常感谢。

在第一个请求测试部分添加:

 pm.environment.set("useridArray",pm.response.json().map((a)=>a.userId))

这里我们使用 map 函数从每个对象获取 userid,map 函数 returns 一个数组。

现在在第二个请求中预请求使用:

let testIDArray = pm.environment.get("useridArray")
pm.environment.set("testID",testIDArray.pop())
pm.environment.set("useridArray",testIDArray)
testIDArray.length ? postman.setNextRequest(pm.info.requestName) : postman.setNextRequest(null)