-
-
Notifications
You must be signed in to change notification settings - Fork 234
/
users-list.js
40 lines (36 loc) · 861 Bytes
/
users-list.js
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
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env node
const process = require('node:process');
const dotenv = require('dotenv');
const zd = require('../src/index.js');
dotenv.config();
const setupClient = (config) => {
return zd.createClient({
username: process.env.ZENDESK_USERNAME,
subdomain: process.env.ZENDESK_SUBDOMAIN,
token: process.env.ZENDESK_TOKEN,
...config,
});
};
/**
*
*/
async function usersList() {
try {
const client = setupClient({debug: false});
const result = await client.users.list();
console.log(
JSON.stringify(
result.map(function (user) {
return user.name;
}),
null,
2,
true,
),
); // Gets the first page
console.log('Total Users: ' + result.length);
} catch (error) {
console.error(`Failed to get list of users: ${error.message}`);
}
}
usersList();