How to read value of response.data.length
I'm trying to build webpage with car database API (just for school purposes) and I'm stuck on this point. I want to request untill all cars will be found (I need to do this in loop cause this API allow to request only 50 cars at once). In this case loop will be sending requests untill number of results will be less than 50 (max) but I can't grab value of response.data.length
and use it in while()
. Is there any method to do this?
My code:
do {
const options = {
method: 'GET',
url: 'https://car-data.p.rapidapi.com/cars',
params: {
limit: '50',
page: '$output_page',
year: input_year,
make: input_brand,
type: input_type
},
headers: {
'x-rapidapi-host': 'car-data.p.rapidapi.com',
'x-rapidapi-key': '*KEY*'
}
};
await sleep(2000);
lengthVar = axios.request(options).then(function(response) {
console.log(response.data);
return response.data.length;
}).catch(function (error) {
console.error(error);
return error;
});
}while((lengthVar % 50) == 0);
from Recent Questions - Stack Overflow https://ift.tt/3omshDZ
https://ift.tt/eA8V8J
Comments
Post a Comment