【问题标题】:Postman Script to set Environment variable邮递员脚本设置环境变量
【发布时间】:2020-04-11 17:25:25
【问题描述】:

我正在为 API 与我们的服务集成之一创建邮递员集合。这里我们使用 OAuth1.0 进行身份验证。我想将 oauth 初始化响应 oauth_tokenoauth_token_secret 设置为邮递员环境变量,以便我可以在进一步的请求中访问它们。 响应采用以下格式而不是 JSON。 oauth_token=oauth_token_value&oauth_token_secret=oauth_token_secret_value&oauth_callback_confirmed=true

我试过下面的脚本:

var output = require('querystring').parse(Response.text);
postman.setGlobalVariable("oauth_token", output.oauth_token);
postman.setGlobalVariable("oauth_token_secret", output.oauth_token_secret); 

请有人帮我将令牌设置为邮递员环境变量。

注意:我使用的是 chrome 插件版本 5.5.4,而不是原生应用。

【问题讨论】:

  • 使用原生应用。

标签: postman


【解决方案1】:

在chrome扩展中你需要使用postman.setEnvironmentVariable():

postman.setEnvironmentVariable("oauth_token", output.oauth_token);
postman.setEnvironmentVariable("oauth_token_secret", output.oauth_token_secret);

为此,您需要创建并选择一个环境(无需手动添加任何变量)。如何做到这一点在这里描述:https://learning.postman.com/docs/sending-requests/managing-environments/#creating-environments

【讨论】:

    猜你喜欢
    • 2019-01-09
    • 2018-12-04
    • 2019-11-14
    • 2019-04-23
    • 2021-01-05
    • 2020-04-05
    • 1970-01-01
    • 2014-01-29
    • 2012-01-19
    相关资源
    最近更新 更多