-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist-queue-members.js
More file actions
30 lines (27 loc) · 1018 Bytes
/
list-queue-members.js
File metadata and controls
30 lines (27 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require('dotenv').config()
const freeclimbSDK = require('@freeclimb/sdk')
const accountId = process.env.ACCOUNT_ID
const apiKey = process.env.API_KEY
// your freeclimb API key (available in the Dashboard) - be sure to set up environment variables to store these values
const freeclimb = freeclimbSDK(accountId, apiKey)
getMembers(queueId).then(members => {
// Use queue members
}).catch(err => {
// Catch Errors
})
async function getMembers(queueId) {
// Create array to store all members
const members = []
// Invoke GET method to retrieve initial list of members information
const first = await freeclimb.api.queues.members(queueId).getList()
members.push(...first.queueMembers)
// Get Uri for next page
let nextPageUri = first.nextPageUri
// Retrieve entire members list
while (nextPageUri) {
const nextPage = await freeclimb.api.queues.members(queueId).getNextPage(nextPageUri)
members.push(...nextPage.queueMembers)
nextPageUri = nextPage.nextPageUri
}
return members
}