# Can you use values from the request body in the response body?

**URL:** <https://community.postman.com/t/can-you-use-values-from-the-request-body-in-the-response-body/12178>\
**Category:** Help Hub\
**Created:** [April 24, 2020, 9:27am UTC](https://community.postman.com/t/can-you-use-values-from-the-request-body-in-the-response-body/12178 "2020-04-24T09:27:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjeefr](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@sjeefr](https://community.postman.com/u/sjeefr)\
**Post date:** [April 24, 2020, 9:27am UTC](https://community.postman.com/t/can-you-use-values-from-the-request-body-in-the-response-body/12178/1 "2020-04-24T09:27:37Z")

</div>

I want the Postman’s mock server respond to a POST request containing JSON values from the request body.

For example,

**request:**

```
{
  "firstName": "John",
  "lastName": "Smith"
}

```

**Response**

```
{
  "existing": true,
  "person": {
    "firstName": {{firstName}},
    "lastName": {{lastName}}
  }
}

```

Would be great if this exists, so we can push our API-first further

---

<div class="post-metadata">

**Author:** ![SabriH](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@SabriH](https://community.postman.com/u/SabriH)\
**Post date:** [April 24, 2020, 3:43pm UTC](https://community.postman.com/t/can-you-use-values-from-the-request-body-in-the-response-body/12178/2 "2020-04-24T15:43:00Z")

</div>

Hey @sjeefr ,

Perhaps there is a better approach than the one I’m suggesting however hopefully it may help you. I’m not entirely sure you’ll be able to accomplish your use case with the mock, but you could also make use of Postman Echo by using the post endpoint [https://docs.postman-echo.com/?version=latest#083e46e7-53ea-87b1-8104-f8917ce58a17](https://docs.postman-echo.com/?version=latest#083e46e7-53ea-87b1-8104-f8917ce58a17) That endpoint should echo the contents of the request body and thus helping you test.

The following suggestion may be better suited for your needs. You could leverage the use of Dynamic Variables i.e [https://learning.postman.com/docs/postman/variables-and-environments/variables-list/#names](https://learning.postman.com/docs/postman/variables-and-environments/variables-list/#names) to generate a random first name and random last name in your example response, e.g:

```auto
{
"firstName": "{{$randomFirstName}}",
"lastName":"{{$randomLastName}}"
}

```

You’d then create environment variables such as `randomfirstName` and `randomlastName` and set the request body to something like:

```auto
{
  "firstName": "{{randomFirstName}}",
  "lastName": "{{randomLastName}}"
}

```

And the final step would be to set up your `test` [scripts](https://learning.postman.com/docs/postman/scripts/test-scripts/) to set the respective values of `randomFirstName` and `randomLastName` from the response body. Example:

```auto
var jsonData = pm.response.json();

pm.environment.set("randomFirstName",jsonData.firstName);
pm.environment.set("randomLastName",jsonData.lastName);

```

Hopefully, you found this information helpful and useful.
