I have two issues that i need help with …
- In API 1 - i want to loop the response body of GET API and find all the “header” that contain “Delete”
When the script finds something that contains “Delete”, grab the announcementid and set it in an array …
the code below,
is finding the ones that don’t say “Delete”, but the array that should show the announcement ids that have delete in them are not showing i need this to show …
var jsonData = pm.response.json();
var resultCount = jsonData.length;
// Test arrays
var hasDelete = ;
var doesntHaveDelete = ;
// Loop through and set arrays with matching data
for (i = 0; i < resultCount; i++) {
var id = jsonData[i].announcementId;
var modelString = jsonData[i].header.toLowerCase();
if (modelString.includes(“Delete”)) {
hasDelete.push({
"announcementId": id,
"hasDelete": modelString.includes("Delete")
});
} else {
doesntHaveDelete.push({
"announcementId": id
});
}
}
// Check that each object in response contained keyword and length matches from test
pm.test(“Expect response to contain Delete”, function() {
console.log(hasDelete);
console.log(doesntHaveDelete);
pm.expect(hasDelete.length).to.equal(resultCount);
});
2nd issue:
Now i want to add that array of AnnouncementIDs and add it to API 2’ endpoint:
and i want to do this as many times as there is a number within the Announcement id array.
Please help …