const axios = require('axios');
const API_URL = 'https://api.explo.co/api/create_customer';
const WAIT_TIME_MS = 60000; // 1 minute
async function createCustomers(customer_post_bodies) {
for (const customer_post_body of customer_post_bodies) {
let successful_call = false;
while (!successful_call) {
try {
const response = await axios.post(API_URL, customer_post_body);
successful_call = true;
} catch (error) {
if (error.response && error.response.status === 429) {
console.warn('Rate limit exceeded. Waiting for 1 minute.');
await new Promise(resolve => setTimeout(resolve, WAIT_TIME_MS));
} else {
console.error(`Error creating customer ${customer.name}:`, error.message);
// TODO: Decide how you want to handle other errors.
}
}
}
}
}