-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoop through tasks to find card and column information.js
More file actions
60 lines (51 loc) · 2.33 KB
/
Loop through tasks to find card and column information.js
File metadata and controls
60 lines (51 loc) · 2.33 KB
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
60
// This code sample is an example of looping through task data for the V3 tasks endpoint.
// Filters set to display all tasks including completed and from archived projects
// A function to display response headers also included. Comment out if you do not require this information.
// Endpoint Url: https://" + siteName + ".teamwork.com/projects/api/v3/tasks.json
// Endpoint documentation: https://apidocs.teamwork.com/docs/teamwork/v3/tasks/get-projects-api-v3-projects-project-id-tasks-json
const myHeaders = new Headers();
const userName = "email address or API KEY here";
const password = "password";
const siteName = "yourSiteName"
let loop = true
let page = 1
let totalTasks = 0
let countCards = 0
myHeaders.append("Authorization", "Basic " + btoa(userName + ":" + password));
const requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow"
};
async function fetchTasks() {
do {
let v3TasksUrl = "https://" + siteName + ".teamwork.com/projects/api/v3/tasks.json?pageSize=500&includeCompletedTasks=true&showCompletedLists=true&includeArchivedProjects=true&fields[cards]=id,column&fields[columns]=id,name,project&include=cards,cards.columns&page=" + page
const response = await fetch(v3TasksUrl, requestOptions)
let data = await response.json()
//console.log(data.tasks);
var tasks = data["tasks"];
var cards = data["included"]["cards"];
var columns = data["included"]["columns"];
var hasMore = data["meta"]["page"]["hasMore"];
//console.log(data.included);
for (const key in tasks) {
if (tasks[key].card != null) {
var taskId = tasks[key].id
var cardId = tasks[key].card.id
var columnId = cards[`${cardId}`].column.id
var columnName = columns[`${columnId}`].name
console.log(`Task Id; ${taskId}`)
console.log(`Card Id; ${cardId}`)
console.log(`Column Id; ${columnId}`);
console.log(`Column Name; ${columnName}\n`);
countCards++
}
totalTasks++
}
console.log(`Page ${page} finished`);
page++
} while (hasMore);
console.log(`Total task on a project board: ${countCards}`);
console.log(`Total requested tasks: ${totalTasks}`);
}
fetchTasks();