I am testing an API that I use a date variable of approx 7 days ago to get data, every now and then the test fails as the environment variable I try set, “id” is undefined. This is because no data has been entered in the last 7 days. When no data is returned it is an empty array.
How should I check if there is data returned before trying to set environment variables
Current structure is
Get the response:
var responseObject = pm.response.json();
Set the env variable:
Have tried a few different If statements but not really sure whether I should be testing the whole response as empty or something as undefined.
Thanks in advance.