Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random variable in json body #620

Open
standej opened this issue Oct 16, 2023 · 5 comments · May be fixed by #3608
Open

Random variable in json body #620

standej opened this issue Oct 16, 2023 · 5 comments · May be fixed by #3608

Comments

@standej
Copy link

standej commented Oct 16, 2023

I exported my tests from postman and imported them in Bruno. In lots of tests I used postman built in feature for random username {{$randomUserName}} or random number {{$randomInt}} and I was putting this dynamic values in json body of the call.
https://learning.postman.com/docs/writing-scripts/script-references/variables-list/
Postman example if i set companyNumber env variable in pre request:
{ "companyNumber": "{{companyNumber}}" }
The problem is that Bruno didnt imported it properly and i can't find a way to put in json body dynamic random environmental variable (string or int).
I tried something like this in script pre request so I get random number:
bru.setEnvVar("companyNumber", Math.round(Math.random() * 100000000));
I checked and Bruno randomize proper value and set env variable properly but i cant put this value inside request json body from env variable.
And in body I tried something like this:
{ "companyNumber": "{{companyNumber}}" }
but without success.
So my question is how I can put dynamic random variable in json body of the request in Bruno?

@UnleashSpirit
Copy link

Hi, same question for header and postman {{$randomUUID}}

@KaniZ0r
Copy link

KaniZ0r commented Oct 19, 2023

@standej it should work if you use bru.setVar instead of bru.setEnvVar

@standej
Copy link
Author

standej commented Oct 19, 2023

Hi @KaniZ0r I tried to do with collection variables and it still dont work:
Here is my json body:
image
Here is what is created in database:
image
And here is value of my variable when i click to eye up:
image
And here is my pre request script how i generate random value:
bru.setVar("loginVar", Math.round(Math.random() * 100000));

Bruno version 0.25.0

Unfortunately still not working and do not interpolate value

@sebastien-savalle
Copy link

It would be nice to provide a feature that allows to generate random values in the json payload directly to simplify the usage.
It could be something similar to the templating feature in Mockoon.

https://mockoon.com/docs/latest/templating/overview/

@robertolopezlopez
Copy link

I usually do something like this:

const { v4: uuidv4 } = require('uuid');
const inputName=uuidv4();
bru.setEnvVar("input_name", inputName);
image

Then in the json body:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants