Tom Kouhsari
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>
0
Comments
Please sign in to leave a comment.
Has the REST API caught-up with this yet?
Hi Dan, Closer. We're tracking getting the group supervisors with "COR-3060". It looks like the work is almost completed, but it might be tied into some other things, so I can't quite tell when it will be generally available. I poked the appropriate people and I'll post back here when I get a response.
Ok, I heard back from the people who know these things. The work is complete and is slated for release 175, which should be out in 3-4 weeks.
Great. Thanks