-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate a time entry.js
33 lines (30 loc) · 1.04 KB
/
Create a time entry.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
//https://apidocs.teamwork.com/docs/teamwork/v1/time-tracking/post-tasks-id-time-entries-json
const myHeaders = new Headers();
const userName = "email address or API KEY here";
const password = "password";
const siteName = "yourSiteName"
const taskId = "taskIdHere"
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic "+btoa(userName+":"+password));
const raw = JSON.stringify({
"time-entry": {
"description": "Time created via API",
"date": "20230801",//YYYYMMDD
"person-id": 256492,
"time": "15:00",
"hours": 4,
"minutes": 35,
"isbillable": true,//Set to false to make time entry non billable
"tags": "API"//Remove this line if you do not want to add a tag
}
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://"+siteName+".teamwork.com/tasks/"+taskId+"/time_entries.json", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));