-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create a budget - Fixed Fee.js
51 lines (48 loc) · 1.55 KB
/
Create a budget - Fixed Fee.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
// Create a fixed feed budget > 50K with a 7% profit and notify user
const myHeaders = new Headers();
const userName = "email address or API KEY here";
const password = "password";
const siteName = "yourSiteName"
const budgetCategory = "budgetCategoryHere"//"STANDARD", "FIXEDFEE"
const capacity = "capacityHere"
const startDate = "startDateHere";
const endDate = "endDateHere";
const projectId = "projectIdHere"
const userId = "userIdHere"
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic " + btoa(userName + ":" + password));
const raw = JSON.stringify({
"budget": {
"budgetCategory": budgetCategory,
"capacity": capacity,
"endDateTime": endDate,
"isRepeating": false,
"notifications": [
{
"notificationMedium": "EMAIL",
"capacityThreshold": 80,
"userIds": [
userId
],
"teamIds": [],
"companyIds": []
}
],
"projectId": projectId,
"startDateTime": startDate,
"type": "FINANCIAL",
"timelogType": "ALL",
"isRetainer": false,
"budgetProfitMargin": 7
}
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch("https://"+siteName+".teamwork.com/projects/api/v3/projects/budgets.json", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));