Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Postman script execution before mockup server response

I am running mock server in Postman which basically sends responses on specific requests. Both response and requests contain Environmental variables of String type which should be unique and I change them before each request to my mock server which is quite annoying.

I would like to have these variables updated by pre-request script before I receive response. I have seen similar question here, but it doesn't work for me — I have tried putting script below to Tests tab to the Request I am mocking response for, but it is not executed.

    function makeid(length) {
        var result           = '';
        var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        var charactersLength = characters.length;
        for ( var i = 0; i < length; i++ ) {
          result += characters.charAt(Math.floor(Math.random() * 
     charactersLength));
       }
       return result;
    }

     pm.environment.set("unique_id", makeid(7));
     pm.environment.set("payment_id", makeid(10));

Please tell if Postman is able at all to execute scripts before sending responses from its Mock server or it is not possible? If it is not able to do so, then are there any ways to automatically update variables before each request?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!