# Dynamic Variable in Request Body Validateion Error

**URL:** <https://community.postman.com/t/dynamic-variable-in-request-body-validateion-error/15227>\
**Category:** Help Hub\
**Tags:** validation, dynamic-variable\
**Created:** [August 21, 2020, 9:30pm UTC](https://community.postman.com/t/dynamic-variable-in-request-body-validateion-error/15227 "2020-08-21T21:30:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![darren.capner](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/darren.capner/32/4730_2.png) [@darren.capner](https://community.postman.com/u/darren.capner)\
**Post date:** [August 21, 2020, 9:30pm UTC](https://community.postman.com/t/dynamic-variable-in-request-body-validateion-error/15227/1 "2020-08-21T21:30:02Z")

</div>

Hi,

I am using a dynamic variable {{$randomInt}} in my request body and the API Designer’s schema validation on for the collection is indicating that there are validation errors.

I am using the following request body in my collections request:

```
{
	"email": "{{email_prefix}}shipper{{$randomInt}}{{$randomInt}}{{$randomInt}}-postmantest{{email_suffix}}",
	"password": "{{PASSWORD}}",
	"firstName": "{{$randomFirstName}}",
	"lastName": "{{$randomLastName}}",
	"phoneNumber": "{{phonenumber}}",
	"companyNumber": {{$randomInt}},
	"companyName": "{{$randomFullName}}",
	"address": "{{$randomStreetAddress}}",
	"city": "Winnipeg",
	"state": "MB",
	"zipCode": "R3C0A5",
	"country": "ca",
	"operateInUS": false,
	"dotNumber": "{{$randomInt}}"
}

```

When I validate the schema for the collection’s request, I end up with the following validation changes suggested.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/5/752c40e12539e962ec8014df7b6047d09bca1549.png)

If I change to not have the {{$randomInt}} in my request body but hard code an integer value, I do not receive any validation errors.

```
{
	"email": "{{email_prefix}}shipper{{$randomInt}}{{$randomInt}}{{$randomInt}}-postmantest{{email_suffix}}",
	"password": "{{PASSWORD}}",
	"firstName": "{{$randomFirstName}}",
	"lastName": "{{$randomLastName}}",
	"phoneNumber": "{{phonenumber}}",
	"companyNumber": 2,
	"companyName": "{{$randomFullName}}",
	"address": "{{$randomStreetAddress}}",
	"city": "Winnipeg",
	"state": "MB",
	"zipCode": "R3C0A5",
	"country": "ca",
	"operateInUS": false,
	"dotNumber": "{{$randomInt}}"
}

```

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/0/03f8a6468091abad8c0d6e64326c489c32852312.png)

---

<div class="post-metadata">

**Author:** ![jecorde](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jecorde/32/14048_2.png) [@jecorde](https://community.postman.com/u/jecorde)\
**Post date:** [July 14, 2023, 7:10pm UTC](https://community.postman.com/t/dynamic-variable-in-request-body-validateion-error/15227/2 "2023-07-14T19:10:18Z")

</div>

Thanks for your post.  
You can create a payload variable in your pre-request script, stringify that Json variable and use it in the body of your request.  
For instance the variables email\_prefix and the variable password could be set in your pre-request script. Inside the pre-request script you can create a Json object and put on those variables. Afterwards, you can JSON.stringify(payload) and use the variable in the body of your request like this: {{payload}}.  
There are some tutorials online regarding using dynamic variables in Postman such as Postman: [The Complete Guide - REST API Testing](https://www.udemy.com/course/postman-the-complete-guide/) along with the postman documentation.  
I hope it helps 🙂

 ![Day_25_Dynamic_variables_30_days_of_Postman](https://us1.discourse-cdn.com/getpostman/original/3X/6/d/6db0aa465324346e68483e9ffd844d68a70da59b.png)

An example of a request body with a payload variable:

 ![Day_10_15_days_of_postman_for_testers](https://us1.discourse-cdn.com/getpostman/original/3X/d/8/d8f21eed356e0d8a3807a7abe238315110be7688.png)
