Skip to content

Commit ba19a4a

Browse files
authored
Create Update a webhook.js
1 parent 08b347b commit ba19a4a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const myHeaders = new Headers();
2+
const userName = "email address or API KEY here";
3+
const password = "password";
4+
const siteName = "yourSiteName";
5+
const webhookId = "webhookIdHere";
6+
const webhookEvent = "TASK.CREATED";//Add your desired wbehook event here - ie: TASK.UPDATED, COMMENT.CREATED - Check out the full list of events here: https://apidocs.teamwork.com/guides/teamwork/webhook-events
7+
const webhookUrl = "webhookUrlHere";// Url for where you would like the webhook payload to be sent ie: https://script.google.com/a/teamwork.com/macros/s/AKfycbzVjDmFeq0u6cfYkFUSazRewr8efg8scfv8sdf8/exec
8+
const apiToken = "userApiToken";//This is not required for the webhook to be created - add your userApiToken for a checksum comparison
9+
myHeaders.append("Content-Type", "application/json");
10+
myHeaders.append("Authorization", "Basic " + btoa(userName + ":" + password));
11+
12+
const raw = JSON.stringify({
13+
"webhook": {
14+
"event": webhookEvent,
15+
"url": webhookUrl,
16+
"version": "2",// Must be version 2
17+
"contentType": "application/json",
18+
"token": apiToken
19+
}
20+
});
21+
22+
const requestOptions = {
23+
method: "PUT",
24+
headers: myHeaders,
25+
body: raw,
26+
redirect: "follow"
27+
};
28+
29+
fetch("https://"+siteName+".teamwork.com/webhooks/"+webhookId+".json", requestOptions)
30+
.then((response) => response.text())
31+
.then((result) => console.log(result))
32+
.catch((error) => console.error(error));

0 commit comments

Comments
 (0)