How do i get the 1st call to run then using the returned value run the 2nd call in a pre-req

I am trying to run the following. I need the 1st call to set the environment variable for the second call.

console.log(“Create tender and flag Accepted”);
var interval = setTimeout(function() {}, 10000),
promiseMethod = function(text) {
var promise = new Promise(function(resolve, reject){
console.log('Enter: ’ + text);
setTimeout(function() {
console.log(‘Complete: ’ + text);
resolve({data: text + ’ 123’});
}, 2000);
return promise;

.then((v) => {return promiseMethod(‘second’);})
.then((v) => {return promiseMethod(‘third’);})
.then((v) => {clearTimeout(interval);});

function first() {
var data = JSON.parse(pm.environment.get(‘data’));

    data.TradingPartnerID = pm.environment.get('ediCustomerTradingPartnerKey');
    data.SendDateTime = pm.environment.get('timestamp');
    data.Header.Load.ShipmentID = "Test" + pm.environment.get('uniqueShipId');
    data.Header.Load.Purpose_Qualifier = "00";
    pm.environment.set("data", JSON.stringify(data));
    const echoPostRequest = {
        url: pm.environment.get('url') + '/edi/tender',
        method: 'POST',
        header: {
            'Content-Type': 'application/json',
            'Authorization': pm.environment.get('currentAccessTokenDev')
        body: JSON.stringify(data)
    pm.sendRequest(echoPostRequest, function(err, res) {
        console.log('4. Ship ID Exist - Load tests');
        pm.test('Creation of tender for test Shipment ID exists not canceled and load', function() {
            pm.expect(res)'code', 200);
            pm.expect(res)'status', 'OK');
        pm.environment.set("tender_id", res.json().data.tender_id);
        console.log("tender_id", res.json().data.tender_id);


function second() {
const acceptTender = {
url: pm.environment.get(‘url’) + ‘/edi/tender’ + pm.environment.get(‘tender_id’) + ‘/accept’,
method: ‘POST’,
header: {
‘Content-Type’: ‘application/json’,
‘Authorization’: pm.environment.get(‘currentAccessTokenDev’)

You need to make the second call in the callback of the first sendRequest, where you have res available.

Why are you making your life so hard dealing with pre-request scripts? You can have everything much cleaner if you would just use “normal” requests.

Because that is the precondition of the test. I have to create the tender, then accept the tender.
So that my call has an accepted tender to run its call. Then i have the test run from it.

Regardless of the test, there is no rule saying 1 Test = 1 Request.

I feel that you are responsible for the technical implementation and for making the tests maintainable.