# Response value is same as in the request sent

**URL:** <https://community.postman.com/t/response-value-is-same-as-in-the-request-sent/59802>\
**Category:** Help Hub\
**Tags:** response, request, responseassertion\
**Created:** [April 10, 2024, 2:41pm UTC](https://community.postman.com/t/response-value-is-same-as-in-the-request-sent/59802 "2024-04-10T14:41:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kayal1postman](https://avatars.discourse-cdn.com/v4/letter/k/a698b9/32.png) [@kayal1postman](https://community.postman.com/u/kayal1postman)\
**Post date:** [April 10, 2024, 2:41pm UTC](https://community.postman.com/t/response-value-is-same-as-in-the-request-sent/59802/1 "2024-04-10T14:41:50Z")

</div>

Hi,  
I need to write automated test for the API response. The response contains values which are same as what I have sent as an request. I need to ensure that what I sent is been added in the database and reflected back in the response with an ID created. Please confirm if the below test is correct?  
const json = pm.response.json();

console.log(json);

let requestData= JSON.parse(request.data);

console.log(requestData);

pm.test(“Data Fields Test against request”,()=\>{  
pm.expect(json.Data).to.deep.equal(requestData.Data);  
}  
)

---

<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:** [April 10, 2024, 4:21pm UTC](https://community.postman.com/t/response-value-is-same-as-in-the-request-sent/59802/2 "2024-04-10T16:21:44Z")

</div>

Can you post an example request and response please? So we can check that they are exactly the same (which would be unusual).

Please use the preformatted text option in the editor when posting code or JSON, so it stops everything from being aligned to the left (and so we can cut and paste). Please don’t post as a screenshot.

In your code, you have…

```auto
let requestData= JSON.parse(request.data);

```

Where is the “request” variable being set?

You have console logs for both variables, what is being shown there? That should be your first troubleshooting step.

You can parse the request body using the following, but please be aware that if you are using variables in your request body, then its not going to pull across the values and your assertion will fail.

```auto
const requestBody = JSON.parse(pm.request.body.raw);
const response = pm.response.json();

console.log(requestBody);
console.log(response);

pm.test('Request body and response match', () => {
    pm.expect(requestBody).to.eql(response);
});

```

---

<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:** [May 10, 2024, 4:22pm UTC](https://community.postman.com/t/response-value-is-same-as-in-the-request-sent/59802/3 "2024-05-10T16:22:02Z")

</div>

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