Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const axios = require('axios');
- const config = require('../config.json');
- const TIMEOUT = 1000 * 60 * 60 * 24; // 24 hours
- const BASE_URL = 'https://api.lever.co/v1';
- async function getCandidates(options) {
- const url = `${BASE_URL}/candidates`;
- const elements = [];
- const updatedAtStart = new Date();
- updatedAtStart.setTime(updatedAtStart.getTime() - TIMEOUT); // 24 h ago
- let next;
- while (true) {
- const response = await axios.get(url, {
- auth: { username: config.lever.apiToken, password: '' },
- params: {
- updatedAtStart: updatedAtStart.getTime(),
- archived: false
- offset: next,
- limit: 100
- }
- });
- next = response.next;
- elements.push(...response.data);
- if (!response.hasNext) break;
- }
- return elements;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement