# JSON POST API - Dynamically change variables within the body & also repeat post for x times

**URL:** <https://community.postman.com/t/json-post-api-dynamically-change-variables-within-the-body-also-repeat-post-for-x-times/35208>\
**Category:** Help Hub\
**Tags:** tests, variables, json\
**Created:** [May 11, 2022, 11:37am UTC](https://community.postman.com/t/json-post-api-dynamically-change-variables-within-the-body-also-repeat-post-for-x-times/35208 "2022-05-11T11:37:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmurru](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@lmurru](https://community.postman.com/u/lmurru)\
**Post date:** [May 11, 2022, 11:37am UTC](https://community.postman.com/t/json-post-api-dynamically-change-variables-within-the-body-also-repeat-post-for-x-times/35208/1 "2022-05-11T11:37:47Z")

</div>

Hello all! i’m somewhat new to postman, so this is perhaps quite a nooby question!  
So i’m learning postman in my own time and the forum’s been really great help but I want to understand the concept of the ‘tests’ functionality.

So, in my example I have a POST API (JSON format), it has a body which has lots of variables but there is only 3 x specific variables of which I want to dynamically change, with each ‘post’.

I found this link which talks about a very similar thing but it eludes me in terms of understanding;

> [@Is it possible to generate requests dynamically?](https://community.postman.com/t/is-it-possible-to-generate-requests-dynamically/26557):
>
> Hi all, My question is: Is it possible to generate requests dynamically? Here is the example: the API documentation is: get /api/books parameter: bookID: Int I want to dynamically generate bookID from 1 to 100. And generate 100 times request to test them. Is there a way to approach this? What I have search: dynamic, dynamically. Related question but no answer: [How to dynamically build a request in Postman?](https://community.postman.com/t/how-to-dynamically-build-a-request-in-postman/13817)

Basically, I have var1, which I want to increase by +1 every time I run the script, for a max of 10 times (i declared a ‘count’ var in my environment for 10, so to run 10 times).

I’ve managed to attain and in turn, make the below TEST script - but I don’t know if it’s right.

```auto
var currentCount = pm.environment.get("count")
var var1count= pm.environment.get("var1")
if (currentCount > 0){
currentCount = currentCount -1 ;
var1count = var1+1 ;
pm.environment.set("count", currentCount);
pm.environment.set("var1count", var1);
postman.setNextRequest("PostAPIExample");
}

```

Also, when I try to declare the var1 within the body, it doesn’t seem to work. It looks like below;

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

Now I don’t know if i’m being silly here - but am I on the right track? and what am I doing wrong?

1.) Is it right that the body of my POST can be dynamically altered and i am declaring the variable correct?  
2.) Does my test script do me justice? and is it even right?
