Postman:有没有办法将带有动态迭代编号的变量传递给请求?

发布于 2025-02-06 01:39:21 字数 639 浏览 2 评论 0原文

摘要: 第一邮递员请求 - 测试选项卡:

let iterationCount = pm.info.iteration+1;
console.log(iterationCount);
const response = pm.response.json();
pm.environment.set(`location_${iterationCount}`,  response.label);

第二邮递员请求

 "CalibrationMask": 
{
               "Length": {{location_${iterationCount}}},
               "Width": 0,
               "Id": "3fc388275b724e82819cf44603db69c3"
 }

当我将上述变量传递给第二个Postman请求时,它不起作用。我在这里想念什么?语法在请求中不正确?请建议

这里的要求是从每次迭代的第一响应中获取值,并将其存储为环境变量 例如:location_1,location_2,location_3,然后将此值传递给同一集合中的后续请求

Snippet:
1st Postman Request - Tests Tab:

let iterationCount = pm.info.iteration+1;
console.log(iterationCount);
const response = pm.response.json();
pm.environment.set(`location_${iterationCount}`,  response.label);

2nd Postman Request

 "CalibrationMask": 
{
               "Length": {{location_${iterationCount}}},
               "Width": 0,
               "Id": "3fc388275b724e82819cf44603db69c3"
 }

When I pass the above variable to 2nd postman request, it doesn't work. What am i missing here? Syntax is incorrect in request? Please suggest

Requirement here is to fetch a value from 1st response for each iteration and store it as environment variable
For eg: Location_1, Location_2 , Location_3 and pass this value to subsequent requests in the same collection

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

征棹 2025-02-13 01:39:21

将两个请求都放在预定脚本中的A中。对于实际请求,请使用示例获取API请求。

Put both the requests within the pre-request script in a for loop; for the actual request, use a sample get api request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文