-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate a task.js
45 lines (42 loc) · 1.59 KB
/
Create 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// This code sample will create a task > assign to a user or users if more are added > notify user(s) > put task on a column if an id is supplied
// Endpoint documentation: https://apidocs.teamwork.com/docs/teamwork/v3/tasks/post-projects-api-v3-tasklists-tasklist-id-tasks-json
const myHeaders = new Headers();
const userName = "email address or API KEY here";
const password = "password";
const siteName = "yourSiteName"
const taskListId = taskListIdHere//integer
const userId = userIdHere//integer
const columnId = columnIdHere//integer
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic "+btoa(userName+":"+password));
const raw = JSON.stringify({
"task": {
"tasklistId": taskListId,
"name": "Creating a task from the Teamwork.com API",
"assignees": {
"userIds": [
userId
]
},
"priority": "medium",
"startAt": "2024-04-16",
"dueAt": "2024-04-24",
"description": "[Create a task endpoint](https://apidocs.teamwork.com/docs/teamwork/v3/tasks/post-projects-api-v3-tasklists-tasklist-id-tasks-json)"
},
"taskOptions" :{
"notify": true // Set to false if no notification is required
},
"card": {
"columnId": columnId
}//Remove this object if you are not setting a column
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://"+siteName+".teamwork.com/projects/api/v3/tasklists/"+taskListId+"/tasks.json", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));