-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStart a timer on a task.js
31 lines (28 loc) · 1.26 KB
/
Start a timer on a task.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
// This code sample will start a timer on a task.
// If you want to start a timer that is not link to a task, you can pass in 0 as the task id or remove the key and value.
// Note that you can only have one timer on task at a time. If you omit the task and start the timer on the project, you can only have one project level timer at a time also.
// Endpoint documentation: https://apidocs.teamwork.com/docs/teamwork/v3/time-tracking/post-projects-api-v3-me-timers-json
const myHeaders = new Headers();
const userName = "email address or API KEY here";
const password = "password";
const siteName = "yourSiteName"
const taskId = "taskIdHere" // intiger 0 if you dont want to link the timer to a task
const projectId = "projectIdHere" // intiger
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic "+btoa(userName+":"+password));
const raw = JSON.stringify({
"timer": {
"taskId": taskId,
"projectId": projectId
}
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://"+siteName+".teamwork.com/projects/api/v3/me/timers.json", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));