How to run two prerequisite (POST and GET) request fir a single method. I want POST method to run first but GET method is running first

My question:

How to run two prerequisite (POST and GET) request fir a single method

Details (like screenshots):
I have one POST method request suppose C. I need to sun to pre request script A (POST method ) and B (GET method) to provide the required parameters for C request. How can i achived that.

I’ve already tried:
I have tried giving two pre request script but its running GET method first and then POST method. I want POST method to run first.

Hi @sudarshan.ohal,

If I understood your question correctly, you want to run 3 different requests and then use response from previous request in next requests.

One way to achieve this is use 3 different requests and have them in collection.

First request will fetch the data and then you can use test to save response in some global or collection variables. That variable can be used in pre test of next request.

Hope this helps :slightly_smiling_face:

@pranavdavar : The solution you are telling me, that i have already implemented. However i dont want to include those two request as a main requests in my collection. I want those to be a pre request scripts. Do you know prioritization in pre request scripts?

Hi @sudarshan.ohal ,

I believe you are using pm.sendRequest() function of postman.

This is asynchronous function.

If you want to wait for the response to arrive then execute the second request, then you may need to use callback function.

Similar type situation I am facing also. I too have 3 requests . I want to run request A & B (A is GET, B is POST) on the pre request tab of request C. So that I can have necessary info to run request C. Problem I am facing is , when I run request C, B is running first and then A is running . That means POST is running first and then the GET. As a result I am unable to execute the request C.
This is my pre request script,

const getOTP = {

method: ‘GET’,

url: ${pm.environment.get('base_url')}/${pm.environment.get('common_path')}/otp-login?msisdn=${pm.environment.get('msisdnWhite')},

header: {

  'User-Agent': 'something',

  'Accept-Language' : 'en'

},

};

const postOTP={

method : 'POST',

url : `${pm.environment.get('base_url')}/${pm.environment.get('common_path')}/otp-login`,

header: {

    'Content-Type':'application/json',

    'Accept-Language':'en'

},

body:{

    mode : 'application/json',

    raw: JSON.stringify(

        {

           "msisdn":"12345666666",

            "otp":"0000"

            } )

}

};

pm.sendRequest(getOTP, (err, response) => {

const jsonResponse = response.json();

pm.environment.set(“GETOTP”,jsonResponse.result)

console.log(jsonResponse);

});

pm.sendRequest(postOTP, (err, response) => {

const jsonData = response.json();

  pm.environment.set("access_token",jsonData.access_token)

});

Any help is much appreciated. Thanks in advance.