# Postman flow, use variable for previous request in body

**URL:** <https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608>\
**Category:** Help Hub\
**Tags:** postman-flows\
**Created:** [October 23, 2023, 1:54pm UTC](https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608 "2023-10-23T13:54:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![security-saganist-14](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/security-saganist-14/32/26260_2.png) [@security-saganist-14](https://community.postman.com/u/security-saganist-14)\
**Post date:** [October 23, 2023, 1:54pm UTC](https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608/1 "2023-10-23T13:54:45Z")

</div>

Hey,  
so i have the following postman flow:  
Request #1: Select “id” variable from the response.  
Request #2: I need to use the “id” from request #1 response, inside the body of request #2 dynamically, I searched through the web but couldn’t find any reasonable solution…

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [October 23, 2023, 1:59pm UTC](https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608/2 "2023-10-23T13:59:12Z")

</div>

Is this the same request as?

[Pre-request-script post take id and put on get request - 🙋 Help - Postman Community](https://community.postman.com/t/pre-request-script-post-take-id-and-put-on-get-request/53603)

Did you just create another account and ask the same question?

If not, then the same advice applies here.

This type of activity is covered in the Postman Learning Centre.

If you are new to Postman, then I would suggest a visit to the Learning Centre.

[Overview | Postman Learning Center](https://learning.postman.com/docs/introduction/overview/)

Including the Postman Training links under “Resources”.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/b/3b763d56d66445f4c34eeb66c64631335559a741.png)

I would recommend the “Galaxy APIs 101” course first as it gets you used to the application features and GUI.

Then the “Galaxy Testing and Automation” course which teaches you how to assert the responses. It includes defining and using variables from responses and chaining requests.

---

<div class="post-metadata">

**Author:** ![security-saganist-14](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/security-saganist-14/32/26260_2.png) [@security-saganist-14](https://community.postman.com/u/security-saganist-14)\
**Post date:** [October 23, 2023, 3:05pm UTC](https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608/3 "2023-10-23T15:05:17Z")

</div>

No because I want to get a variable from a post, that’s easy, and then where I’m stuck is how to put the variable inside another post, not a get

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [October 23, 2023, 4:15pm UTC](https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608/4 "2023-10-23T16:15:38Z")

</div>

It doesn’t really matter whether its a GET or POST request.

The only thing that really matters is whether its a query parameter or a JSON body.

Even then, that doesn’t really matter as in both scenarios, you save the variable from the initial Post request to a collection or environment variable then reference it using {{variableName}} either in the JSON body or the query param.

You can use the following link for more details on how to store and use variables.

[Store and reuse values using variables | Postman Learning Center](https://learning.postman.com/docs/sending-requests/variables/)

The Galaxy Testing and Automation course has an example of this flow.

What you are trying to do is Postman basics, hence the advice to try those Learning Centre resources.

---

<div class="post-metadata">

**Author:** ![security-saganist-14](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/security-saganist-14/32/26260_2.png) [@security-saganist-14](https://community.postman.com/u/security-saganist-14)\
**Post date:** [October 23, 2023, 4:54pm UTC](https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608/5 "2023-10-23T16:54:25Z")

</div>

Thanks, all this time i thought my variable isn’t working but the problem is different, as soon as i input a variable in the body, the signature calculation script i use breaks… since it take the variable and not the value of the variable  
is there any way to fix it?

script below:

var timestamp = (Math.floor(new Date().getTime() / 1000) - 10).toString();  
postman.setGlobalVariable(“rapyd\_request\_timestamp”, timestamp);

var signature\_salt = CryptoJS.lib.WordArray.random(12);  
postman.setGlobalVariable(“rapyd\_signature\_salt”, signature\_salt);

var body = ‘’;  
if (JSON.stringify(request.data) !== ‘{}’ && request.data !== ‘’ && typeof request.data !==‘object’ ){  
body = JSON.stringify(JSON.parse(request.data));  
}  
var secret = pm.environment.get(‘rapyd\_secret\_key’);  
var to\_sign = request.method.toLowerCase() + request.url.replace(‘{{base\_uri}}’,‘/v1’) + signature\_salt + timestamp + pm.environment.get(‘rapyd\_access\_key’) + secret + body;

console.log("to\_sign " + to\_sign);  
var rapyd\_signature = CryptoJS.enc.Hex.stringify(CryptoJS.HmacSHA256(to\_sign, secret));  
rapyd\_signature = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(rapyd\_signature));  
console.log("rapyd\_signature " + rapyd\_signature);  
postman.setGlobalVariable(“rapyd\_signature”, rapyd\_signature);

‫בתאריך יום ב׳, 23 באוק׳ 2023 ב-19:25 מאת ‪Mike Jones via Postman Community‬‏ \<‪[notifications@getpostman.discoursemail.com](mailto:notifications@getpostman.discoursemail.com)‬‏\>:‬

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [October 24, 2023, 9:45am UTC](https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608/6 "2023-10-24T09:45:00Z")

</div>

Which variable are you having issue with?

At a glance, it might be the {{base\_uri}}

You can only use {{variableName}} in certain places, like the URL and body.

Also it looks like you have wrapped the {{base\_uri}} in quotes which means it will treat it as a string instead of the variable.

You also appear to be mixing the old postman method instead of using the recommended pm method in a few places (postman.setGlobalVariable for example instead of pm.globals).

On a side note, do you really need these to be global variables (available to all collections in Postman). They probably should be collection or ideally environment variables.

When posting code or JSON responses on the forum, please use the preformatted text option in the editor which stops everything from being aligned to the left (and also keeps the correct formatting for the quotes).

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [November 23, 2023, 9:45am UTC](https://community.postman.com/t/postman-flow-use-variable-for-previous-request-in-body/53608/7 "2023-11-23T09:45:02Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
