【问题标题】:How can I edit/update environment variables using a run in postman button?如何使用在邮递员中运行按钮编辑/更新环境变量?
【发布时间】:2020-11-18 00:53:43
【问题描述】:

我正在尝试使用在邮递员中运行按钮。我在文档 (https://learning.postman.com/docs/publishing-your-api/run-in-postman/run-button-API/) 中看到了有关如何编辑现有环境的说明。但我发现不清楚如何实现提供的代码。

我希望我的 run in postman 按钮根据从该按钮所在的页面发送的值具有不同的环境变量。本质上是根据 html 中的当前值编辑环境以具有值。

谁能解释文档中的这段代码在做什么以及它应该去哪里(也就是在 javascript 或邮递员测试中)?

来自邮递员文档 (https://learning.postman.com/docs/publishing-your-api/run-in-postman/run-button-API/):

更新环境的 API 密钥:

function () {


var stagingKey = document.getElementById('staging-key-input').value,
    productionKey = document.getElementById('production-key-input').value,
    preventOveride = true;
    runButtonIndex = 0,
    envData = {
      stagingKey: stagingKey,
      productionKey: productionKey
    };

  _pm('env.assign', 'API Keys', envData, preventOveride, runButtonIndex);
}

提前致谢!

【问题讨论】:

    标签: api postman


    【解决方案1】:

    env.assign 方法会更新您嵌入的现有环境以及“在 Postman 中运行”按钮中的集合。您需要从按钮所在的页面调用匿名函数。

    我有 a code sample 创建一个新环境(不是编辑现有环境),但过程是相似的。在我的示例中,JavaScript 函数在使用onsubmit 提交 HTML 表单时执行。

    【讨论】:

      猜你喜欢
      • 2018-01-19
      • 2019-01-09
      • 2021-10-31
      • 2020-11-06
      • 2021-01-05
      • 2017-08-11
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多