邮递员脚本设置环境变量

时间:2019-12-19 06:21:12

标签: postman

我正在创建一个与我们的服务进行API集成的邮递员集合。在这里,我们使用OAuth1.0进行身份验证。我想将oauth初始响应 oauth_token oauth_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,而不是本机应用程序。

1 个答案:

答案 0 :(得分:0)

在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