-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.js
59 lines (45 loc) · 1.54 KB
/
example.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const createAsanaClient = require("./index");
const TOKEN = process.env.TOKEN;
if (!TOKEN) {
console.log("No persontal access token found! Run as:");
console.log(" TOKEN=xxxxxxxxxx node example.js");
process.exit(1);
}
const asana = createAsanaClient(TOKEN);
const formatTitle = x => `\x1b[36m========== ${x} ==========\x1b[0m`;
const formatResultList = xs => xs.map(x => `${x.name} \x1b[33m(${x.id})\x1b[0m`).join("\n") + "\n";
let firstWorkspaceId, firstWorkspaceName;
// fetch all workspaces for user
asana.getWorkspaces()
.then(workspaces => {
console.log(formatTitle("Workspaces"));
console.log(formatResultList(workspaces));
firstWorkspaceId = workspaces[0].id;
firstWorkspaceName = workspaces[0].name;
})
// fetch members of first workspace
.then(() => asana.getMembers(firstWorkspaceId))
.then(members => {
console.log(formatTitle(`Members (${firstWorkspaceName})`));
console.log(formatResultList(members));
})
// fetch projects of first workspace
.then(() => asana.getProjects(firstWorkspaceId))
.then(projects => {
console.log(formatTitle(`Projects (${firstWorkspaceName})`));
console.log(formatResultList(projects));
})
// create a new task for the first project
.then(() => asana.addTask({
workspace: firstWorkspaceId,
// projects: ["00000000000000"],
// assignee: "00000000000000",
name: "Do something",
notes: "Foo\nBar\nBaz",
}))
.then(task => {
console.log(formatTitle("New task"));
console.log(task)
})
// or display the error
.catch(err => console.log(err.stack));