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:“[email protected]”,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