I am currently trying to run 2 POST requests in my pre-request script for a PUT request, one for Authentication and the other for POSTING dummy information to be used for the PUT request test. I am currently running into a problem that is preventing me from completing the PUT request. The two post requests run in the prerequest, but the PUT request is never run⌠it just leaving the request hanging in Postman, and with Newman, the request is run, but returns a 404 with the variables at the end of the URL never set.
My PUT URL
https://{{SecureURL}}/api/v1/drivers/{{driver_id}}
I am wondering if it is possible to run mutliple POT requests within a pre-request?
If so, I am wondering what I am doing wrong thenâŚ
My Pre Request script:
// This API needs to have the 404 response fixed, currently returns a 400
// Set UTC timestamp to environment variable
driverNumber = Math.floor(Math.random() * 9000000000) + 1000000000;
pm.environment.set(âtimestampUtcIso8601â, (new Date()).toISOString().toLowerCase());
pm.environment.set(âuserâ, pm.environment.get(âtimestampUtcIso8601â));
pm.environment.set(ânumberâ, driverNumber);
pm.sendRequest({
url: âhttps://â + pm.environment.get(âSecureURLâ) + â/api/v1/auth/loginâ,
method: âPOSTâ,
header: {
âAcceptâ: âapplication/jsonâ,
âContent-Typeâ: âapplication/x-www-form-urlencodedâ,
âUser-Agentâ: âtestâ
},
body: {
mode: âurlencodedâ,
urlencoded: [
{key: âUsernameâ, value: pm.environment.get(âAdminUserâ), disabled: false},
{key: âPasswordâ, value: pm.environment.get(âWebPasswordâ), disabled: false}
]
}
}, function (err, res) {
if(err) {
console.log(âAn error occurred, please reviewâŚâ);
console.log(err);
} else {
pm.expect(res).to.have.property(âcodeâ, 200);
pm.environment.set(âtokenâ, "Token " + res.json().token);
pm.environment.set(âsubscriberIdâ, res.json().subscriberId);
}
});
pm.sendRequest({
url: âhttps://â + pm.environment.get(âSecureURLâ) + â/api/v1/driversâ,
method: âPOSTâ,
header: {
âAuthorizationâ: pm.environment.get(âtokenâ),
âAcceptâ: âapplication/jsonâ,
âContent-Typeâ: âapplication/jsonâ,
âUser-Agentâ: âtestâ
},
body: {
mode: ârawâ,
raw: JSON.stringify({startLocation:{address:{fullAddress:"\n, â,fullAddressInLine:â, , â,line1:â1133 Louisiana Avenueâ,city:âWinter Parkâ,state:âFLâ,zip:â32789â},latitude:28.4813018,longitude:-81.4387899},endLocation:{address:{fullAddress:â\n, â,fullAddressInLine:â, , â,line1:â1133 Louisiana Avenueâ,city:âWinter Parkâ,state:âFLâ,zip:â32789â},latitude:28.4813018,longitude:-81.4387899},user:{firstName:âTestâ,lastName:âTestâ,Username:â",Password:"",userId:"",role:"",isPasswordChangeRequired:false,email:âzbaker@productivityapex.comâ,username: pm.environment.get(âuserâ),newPassword:âtestâ},vehicle:{},earliestStartTimeDate:âWed Aug 01 2018 07:00:00 GMT-0400 (Eastern Daylight Time)â,restBreakDurationDate:âWed Aug 01 2018 01:00:00 GMT-0400 (Eastern Daylight Time)â,maximumWorkingHours:9,maximumDrivingHours:8,fixedCost:0,costPerMile:0,costPerHour:0,restBreakWindows:[{startTime:â2018-07-13T16:44:30.375Zâ,endTime:â2018-07-14T02:14:30.375Zâ}],color:"#ff0000",tags:[{text:âtestâ},{text:âtagâ}],skills:[{text:âtestâ},{text:âskillâ}],driverNumber: pm.environment.get(ânumberâ),phoneNumber:â3213131313â,earliestStartTime:â07:00:00â,restBreakDuration:â01:00:00â,customFields:{}} )
}
}, function (err, res) {
pm.expect(res).to.have.property(âcodeâ, 200);
pm.environment.set(âdriver_idâ, res.json().id);
pm.environment.set(âdriverUserIdâ, res.json().userId);
pm.environment.set(âoriginalDriverObjâ, JSON.stringify(res.json()));
});
Please help, as I am currently running