pm.sendRequest not working in post request Test

I created a method in collection level prerequest script as follows :

utils = {

  testPMReq : function() {
       console.log("I am here");
        pm.sendRequest("https://postman-echo.com/get", function (err, response) {
        console.log(response.json());
    }); 
  }
};

and then used this method in a post request test as follows :

utils.testPMReq();

It prints out: β€œI am here” but it doesnt execute the pm.sendRequest call.

When I call utils.testPMReq(); in collection level pre-prequest script right after method creation, it executes the send request call.

Can someone please help why sendRequest is not working when I execute the method from post request script and how I can make it work?

1 Like

My issue was to send some headers that should not be sent with a get request. This happened by copying the post request headers for the get request.

I hope it helps somone :slight_smile: .