0

I create users for the DB. I need to send name and email. They should be unique, but not random. For example, the first user:

{
    "Name": "Panda",
    "Email": "pandaemail@test.com"
}

Then I need run collection with this request and automatically add 1 in the each following request for user creation.

User 2 should be:

{
    "Name": "Panda1",
    "Email": "panda1email@test.com"
}

User 3:

{
    "Name": "Panda2",
    "Email": "panda2email@test.com"
}

And so on. How can I do this in Postman?

Tanya
  • 1
  • 2

1 Answers1

0

Step 1: Set a variable in environment. For example, counter=1

Step 2: in Pre-request script:

let counter = pm.environment.get('counter');

if (typeof(counter) === 'string'){
    counter = Number.parseInt(counter);
}

let name = "Panda" + counter;
pm.environment.set('name', name);

let email = "Panda" + counter + "email@test.com";
pm.environment.set('email', email);

pm.environment.set('counter', counter + 1);

Step 3: in Body:

{
    "Name": "{{name}}",
    "Email": "{{email}}"
}
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20