You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何设置Postman以使用pm.globals.set替代postman.setGlobalVariable?

Fixing pm.globals.set() Not Working in Postman

Hey there! I totally get the confusion—switching between old and new Postman APIs can be tricky. Let's break down why pm.globals.set("id","12345") isn't working for you, and how to fix it.

The Root Cause

The pm.* API (including pm.globals.set()) was introduced in Postman v5.0 as the modern replacement for older methods like postman.setGlobalVariable(). If your Postman version is older than v5.0, the pm namespace won't be available at all. Even if you're on a slightly newer version, there might be compatibility bugs blocking it from working properly.

Step-by-Step Fix

Here's how to get up and running with the modern API:

  • Check your Postman version
    Open Postman, click the Postman icon in the top-left corner, go to Settings → About. Look for the version number—if it's below v5.0, that's definitely the issue.

  • Upgrade to the latest Postman version
    Head over to the official Postman download page to grab the newest desktop version. After installing, restart Postman completely to ensure the new API loads properly.

  • Verify the fix
    Once upgraded, go to your Tests tab and enter:

    pm.globals.set("id", "12345");
    // Add this line to confirm it worked
    console.log("Global variable set:", pm.globals.get("id"));
    

    Send your request, then check the Console (bottom-left of Postman) to see if the log shows the correct value. You can also verify manually by clicking the eye icon in the top-right to open Globals—the id variable should appear with the value "12345".

Bonus Note

The old postman.setGlobalVariable() method is now deprecated, meaning it might be removed in future versions. Using pm.globals.set() is better because it’s part of a more consistent, feature-rich API—you’ll also get access to handy extras like pm.globals.unset() to delete variables, or pm.environment for environment-specific storage.

内容的提问来源于stack exchange,提问作者colin_dev256

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:54:27