I am trying to figure out the best way to call this API multiple times and compile all the calls into one list of json. This API only allows a limit of 50 users(json data items) per call. The only thing that will change from call to call is the filter params. Ex: params: {"filter: skip=50"} would skip the first 50 and the next call would be skip=100. The code below would be the first call. I am trying to not manually do the calls because depending on how many people are in the campaign we are running I might have to run this 50+ times.
const router = express.Router();
const api_secret = process.env.API_SECRET
router.get('/', (req, res) => {
const options = {
method: 'GET',
url: 'https://app.viral-loops.com/api/v2/participant_rank',
params: {apiToken: api_secret},
headers: {'Content-Type': 'application/json'}
};
axios.request(options).then(function (response) {
let array = response.data.data
let newUser = array.map(user => { return {user: {
"firstname": user.user.firstname,
"lastname": user.user.lastname,
"rank": user.user.rank,
"country": user.user.extraData.Vm7Tt6MH,
"team": user.user.extraData._0bCLLf,
"referrals": user.counters.referrals.total
}}})
res.json(newUser)
}).catch(function (error) {
console.error(error);
});
});
app.use('/.netlify/functions/fetch-leaderboard', router);