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

无需预请求脚本重复使用Postman动态变量值可行吗?

Reuse Same Dynamic Variable Value in Postman Request Body Without Pre-Request Script

Great question! I’ve run into this exact issue before with Postman’s dynamic variables—each time you call {{$randomFirstName}}, it generates a new random value, which is why your description and first_name fields ended up with different names.

Luckily, you can achieve the inline variable assignment you’re looking for using Postman’s built-in pm.variables.set() method directly in your request body. Here’s how it works:

{
  "description": "{{$pm.variables.set('firstName', $randomFirstName)}}'s Home",
  "first_name": "{{firstName}}",
  "last_name": "{{$randomLastName}}",
  "more_fields": "..."
}

How This Works:

  • $pm.variables.set('firstName', $randomFirstName) generates a single random first name, stores it in a temporary request-level variable called firstName, and returns the generated value immediately. This means your description field will still show something like "John's Home" as expected.
  • The first_name field then references the {{firstName}} variable, which pulls the exact same value stored earlier—no new random generation happens here.
  • This temporary variable only exists for the duration of the current request, so it won’t clutter your environment/global variables or affect other requests.

This approach keeps everything self-contained in the request body, just like you wanted, without needing to add extra pre-request script logic.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 00:44:06