Postman API -how将环境变量传递给另一个请求jason体

问题描述 投票:2回答:2
  1. 我创建了全局变量。将其设置为Test作为env变量,相应的引用ID存储在Create GLVar中

pm.test("Status code is 200", function () { pm.response.to.have.status(200);}); var jsonData = pm.response.json(); pm.environment.set("CreateGLVar",jsonData.result.quoteID);

用于在Env变量中存储值的脚本

  1. 我可以知道如何使用存储在CreateGLVar中的值作为以下脚本。我如何从全局变量的第一个请求中引用id并在第二个请求中动态插入(如下所示)。

get quote id

enter image description here

postman
2个回答
3
投票

Postman使用双花括号来插入变量,这些变量也可以在原始请求体中使用。

在您的具体情况下,您可以使用:

"quoteID": "{{quoteIdVariable}}"

我使用的是Postman Chrome扩展版5.3.1,这对我有用。

修改:现在已弃用Chrome扩展程序,这仍适用于Postman桌面应用


0
投票

谢谢亚伦。

当我使用“quoteID”时,我获得了成功:“{{quoteIdVariable}}”在我的绑定API.my 2 API在我单独执行时工作正常。

但是当我将API作为集合(Quote和Bind API)执行时,我遇到了问题。如果我作为集合执行,我在这里失踪了。

enter image description here enter image description here

Execution failed Failedenter image description here

© www.soinside.com 2019 - 2024. All rights reserved.