Axios Request failed with status code 429 but it is working with Postman

I am trying to access this API using axios but I am getting error with status: 429 [ Too many Requests ]. I am sending only one requests still getting an error.

BUT when I try to access this url using postman it is working.

axios .post( ` ) .then(result => { console.log(result.data); }) .catch(err => { console.log(err); });
4

2 Answers

I ran into this same issue and this happens because of too many requests.

You are probably running the above line inside some loop which is causing this to happen as Axios is firing off all requests simultaneously.

The workaround would be to await the response, something like this

try { const result = await axios.post(`YOUR_URL`, {<Your JSON payload>});
} catch (error) { console.error(error);
}

Please note the above code has to be inside an async function.

use retry-axios:

const axios = require('axios');
const retry = require('retry-axios');
const params = { responsive: true, destination: 'New+York%2C+New+York', latLong: '40.75668%2C-73.98647', regionId: 178293, startDate: '01%2F20%2F2019', endDate: '01%2F21%2F2019', rooms: 1, adults: 2, timezoneOffset: 19800000, langid: 1033, hsrIdentifier: 'HSR', page: 7
}
const raxConfig = { backoffType: 'exponential', onRetryAttempt: (err) => { const cfg = rax.getConfig(err); const status = err.response.status; console.log(`🔄 [${status}] Retry attempt #${cfg.currentRetryAttempt}`); }
}
axios .post( ' {}, { params, raxConfig, } ) .then(result => { console.log(result.data); }) .catch(err => { console.log(err); });

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like