-
Notifications
You must be signed in to change notification settings - Fork 2
/
CAAC_Outbound_Integration.txt
80 lines (66 loc) · 2.63 KB
/
CAAC_Outbound_Integration.txt
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/******************************************************************************
* Outbound integrations
*
* Outbound integrations are triggered when an xMatters system action occurs,
* such as when an event status changes, a notification is delivered, or a
* recipient responds to a message. These system actions are called 'triggers'.
*
* Outbound integrations can perform tasks such as initiating a follow-up xMatters
* event when the status of an event changes or updating another system in your
* toolchain when a user responds to a notification.
*
* xMatters passes information about the trigger to the outbound integration
* as a JSON object in the body of the built-in request object. Your outbound
* integration can process this data and use it in the script. (To include form
* properties in the request data, select 'Include in Outbound Integrations'
* from the property's settings on the form layout.)
*
* The following sample code shows how to work with scripts in the Integration
* Builder. You can use it as a template and then customize it to work with your
* integration.
******************************************************************************/
/**
* Parse the payload data
*
* This code shows how to extract the payload from the built-in request object.
* The specific fields that are included in the payload depends on the type of
* trigger and how many form properties are included.
*/
var payload = JSON.parse(request.body);
if (payload.eventProperties && Array.isArray(payload.eventProperties)) {
var eventProperties = payload.eventProperties;
payload.eventProperties = {};
for (var i = 0; i < eventProperties.length; i++) {
var eventProperty = eventProperties[i];
var key = Object.keys(eventProperty)[0];
payload.eventProperties[key] = eventProperty[key];
}
}
console.log ('postback_url = ' + payload.eventProperties.postback_url);
console.log('response = ' + payload.response);
switch (payload.response) {
case 'Set To Open':
SetToOpen();
break;
}
function SetToOpen(){
var newnotes = payload.eventProperties.notes + '<br>' + payload.date + ' - Moved to Open by user ' + payload.recipient + ' via ' + payload.device + ' with comment - ' + payload.annotation;
var trigger = JSON.stringify({
"Defect":
{
"State": "Open",
"Notes": newnotes
}
});
console.log( 'Response payload: ' + JSON.stringify( trigger ) );
var req = http.request({
method: 'POST',
endpoint: 'CAAgile',
path: payload.eventProperties.postback_url,
headers: {
'Content-Type': 'application/json',
'Cookie': 'ZSESSIONID=_G0HXXXXXQ9yLnbnLP8sp9XXXXXTsEiOtWFDXXXXXX'
}
});
req.write(trigger);
}