0

I am new with Postman > Pre-request Script, Can you help me create a random email value for my API Request. Thank you in advance.

1

You can simply generate a UUID and append it to a domain.

const uuid = Math.random().toString(36).substring(2, 15) +
        Math.random().toString(36).substring(2, 15);
const email = "user_" + uuid + "@myDomain.com";
pm.environment.set("currentEmail", email);

Reference: https://stackoverflow.com/a/13403498/2252076

Then, you can reference the {{currentEmail}} variable anywhere on the request or on the tests.

0

I tried the same way as shown above and got the following error I am trying to create a random number for one of my field and writing the same test in pre-request scripts. { "errors": [ { "message": " Could not decode JSON, syntax error - malformed JSON.", "code": 500, "path": "id.default" } ] }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.