# How can I use variables in "postRequest" headers and body?

**URL:** <https://community.postman.com/t/how-can-i-use-variables-in-postrequest-headers-and-body/24623>\
**Category:** Help Hub\
**Tags:** tests, variables, collections, json\
**Created:** [June 7, 2021, 10:03pm UTC](https://community.postman.com/t/how-can-i-use-variables-in-postrequest-headers-and-body/24623 "2021-06-07T22:03:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sero.barseghyan](https://avatars.discourse-cdn.com/v4/letter/s/cc9497/32.png) [@sero.barseghyan](https://community.postman.com/u/sero.barseghyan)\
**Post date:** [June 7, 2021, 10:03pm UTC](https://community.postman.com/t/how-can-i-use-variables-in-postrequest-headers-and-body/24623/1 "2021-06-07T22:03:05Z")

</div>

\*\*In the tests there is a need to use “postRequest” but there are required headers for that request. For the current headers are set variables \*\*

This is the example, but does not work:

const postRequest = {  
url: `${pm.variables.get('url')}://${pm.variables.get('host')}/${pm.variables.get('path_prefix')}/v2/example/add`,  
method: ‘POST’,  
header: {  
‘Content-Type’: ‘application/json’,  
**’User’: ‘{{user}}’,**  
**’id’: '{{id}}'**  
},  
body: {  
**newId: ‘{{newID}}’,**  
raw: JSON.stringify({ key: ‘this is json’ })  
}  
};  
pm.sendRequest(postRequest, (error, response) =\> {  
console.log(error ? error : response.json());  
});

_My question_:

1. How can use the already set variables as a Header value in the “postRequest” ?
2. How can use the already set variables as a Body key’s value in the “postRequest” ?

_Details (like screenshots)_:

_How I found the problem_:

_I’ve already tried_:

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [June 7, 2021, 11:34pm UTC](https://community.postman.com/t/how-can-i-use-variables-in-postrequest-headers-and-body/24623/2 "2021-06-07T23:34:31Z")

</div>

you can use:

```
pm.variables.replaceIn("this will replace {{user}} with user variable value")
```
