-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvite client user to site.js
51 lines (48 loc) · 1.86 KB
/
Invite client user to site.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
// This code sample will invite a client user to your site
// There is also logic to add the client user to projects in the specified company
// Note that client users can not be invited to the owner company
// Endpoint documentation: https://apidocs.teamwork.com/docs/teamwork/v1/people/post-people-json
const myHeaders = new Headers();
const userName = "email address or API KEY here";
const password = "password";
const siteName = "yourSiteName"
const companyId = companyIdHere // integer
const projectIds = "projectIdsHere" // comma separated list of project ids - leave enpty string if no projects are required at time of invite
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Basic "+btoa(userName+":"+password));
const raw = JSON.stringify({
"person": {
"email-address": "[email protected]",
"user-name": "[email protected]",
"first-name": "firstName",
"last-name": "lastName",
"company-id": companyId,
"sendInvite": true,// Set to false you do not want an invite to go out straight away
"sendInviteWithMessage": "",
"receiveDailyReports": true,
"administrator": false,
"canAddProjects": true,
"canManagePeople": false,
"canAccessAllProjects": false,
"accessProjectIds": projectIds,
"accessProjectsCompanyIds": "",
"setProjectAdmin": false,
"getUserDetails": true,
"isClientUser": true,// Client user flag
"continueIfUserExists": false,
"user-type": "account",
"canCreateProjects": false,
"canAddUsers": false
},
"assignDefaultProjects": false
});
const requestOptions = {
method: "POST",
headers: myHeaders,
body: raw,
redirect: "follow"
};
fetch(`https://${siteName}.teamwork.com/people.json`, requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));