# How to get the request body raw inside test cases in TESTS scripts?

**URL:** <https://community.postman.com/t/how-to-get-the-request-body-raw-inside-test-cases-in-tests-scripts/43937>\
**Category:** Help Hub\
**Created:** [February 13, 2023, 11:44pm UTC](https://community.postman.com/t/how-to-get-the-request-body-raw-inside-test-cases-in-tests-scripts/43937 "2023-02-13T23:44:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![qa-edts](https://avatars.discourse-cdn.com/v4/letter/q/a88e4f/32.png) [@qa-edts](https://community.postman.com/u/qa-edts)\
**Post date:** [February 13, 2023, 11:44pm UTC](https://community.postman.com/t/how-to-get-the-request-body-raw-inside-test-cases-in-tests-scripts/43937/1 "2023-02-13T23:44:30Z")

</div>

I am trying to get the request body raw inside test cases in TESTS scripts?  
Here the script in TESTS:

pm.sendRequest({

```
url: pm.collectionVariables.get("url") + '/xxxxx/'+ api +'/xxxxxxxxxxx',
method: 'POST',
header: {
    'content-type': 'application/json',
    'application': pm.collectionVariables.get("sha256"),
    'sign': pm.collectionVariables.get("sign")
},
body: {
    mode: 'raw',
    raw: JSON.stringify({
        deviceId: null,
        email: null
    })
}

```

}, console.log(“Request Body :”, JSON.parse(pm.request.body.raw)),  
function (err, res) {  
pm.test(“N : All Parameter Null”, function () {  
pm.expect(res).to.have.property(‘code’, 200);  
pm.expect(res.json()).to.have.property(‘status’, ‘00’);  
pm.expect(res.json()).to.have.property(‘message’, ‘Success’);  
console.info("All Parameter Null Response Time: " + res.responseTime)  
});  
})

I’m using console.log(“Request Body :”, JSON.parse(pm.request.body.raw)) to get request body raw, but the content i got is the raw data from BODY (Main Test Cases)

the purpose of this question is to create a signature in the header, based on request body raw that generated with secret key  
i have no problem to create signature in BODY (Main Test Cases), the problem only inside TESTS

How can I get the request body from TESTS ?  
or anyone experience how to create signature inside TESTS?

---

<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:** [February 14, 2023, 1:07pm UTC](https://community.postman.com/t/how-to-get-the-request-body-raw-inside-test-cases-in-tests-scripts/43937/2 "2023-02-14T13:07:09Z")

</div>

If you have a look at the sendRequest() info in the Postman JavaScript reference.

[Postman JavaScript reference | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#sending-requests-from-scripts)

You can define the request as its own object, which should give you full access to the body to add or remove whatever you want before you hit the sendRequest. You are in full control of what goes in the body.

```auto
// Example with a full-fledged request
const postRequest = {
  url: 'https://postman-echo.com/post',
  method: 'POST',
  header: {
    'Content-Type': 'application/json',
    'X-Foo': 'bar'
  },
  body: {
    mode: 'raw',
    raw: JSON.stringify({ key: 'this is json' })
  }
};

pm.sendRequest(postRequest, (error, response) => {
  console.log(error ? error : response.json());
});

```
