0

Get Group Supervisors

Context

Javascript code to get a group's supervisors using the SOAP API. This can be used by the Integration Builder.

Usage

supervisors = getGroupSupervisors("Database");
for (var i = 0; i < supervisors.length; i++) {
console.log(supervisors[i]);
}

Code

/**
* Returns the list of supervisors for a group
* @param {String} groupName
* @return {Array} groupSupervisors - array of supervisor usernames
*/
function getGroupSupervisors(groupName) {
var soapRequestBody = constants.QueryGroupRequest.replace("__GROUPNAME__", groupName);
var soapRequest = http.request({
"endpoint" : "xMatters",
"method" : "POST",
"path" : "/api/services/xmatters-5.5.47"
});

var soapResponse = soapRequest.write(soapRequestBody);

var doc = new XMLUtils.DOMParser().parseFromString(soapResponse.body);
var select = XMLUtils.xpath.useNamespaces({"ns": "http://www.xmatters.com/webservices/schema#5.5.47"});

var status = select("//ns:return/ns:status/text()", doc);
if (status != "OK") {
// If status is not ok, then group was not found
return null;
}

var supervisors = select("//ns:supervisor/ns:name/text()", doc);
var groupSupervisors = [];
for (var i = 0; i < supervisors.length; i++) {
groupSupervisors.push(supervisors[i]);
}
return groupSupervisors;
}

 

This code requires a constant named QueryGroupRequest with the following value (replace the italicized placeholders with your username, password and company):

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:sch="http://www.xmatters.com/webservices/schema#5.5.47">
<soap:Header/>
<soap:Body>
<sch:QueryGroup>
<sch:user>YOURUSER</sch:user>
<sch:password>YOURPASSWORD</sch:password>
<sch:clientTimestamp></sch:clientTimestamp>
<sch:clientIP></sch:clientIP>
<sch:clientOSUser></sch:clientOSUser>
<sch:company>YOURCOMPANY</sch:company>
<sch:groupName>__GROUPNAME__</sch:groupName>
</sch:QueryGroup>
</soap:Body>
</soap:Envelope>

 

4 comments

Please sign in to leave a comment.