
I have an outbound integration that is triggered by the submission of a form via the xMatters portal. This outbound integration parses the content from the form, executes some business logic and then makes an API call to an inbound integration to send an alert.
The downside is that I end up with two events. The one that is created when the form is submitted and the one that is created by the call to the inbound integration. I would like to add some code at the end of the outbound integration to automatically terminate the first event (the one created by the form). I assume the best way to do that is call the event API to change the status of the event but I can't seem to get it to work. Tried fetch and AJAX and neither works. Google seems to have run out of ideas. Anybody have any suggestions?
This is the most recent code that didn't work.
var eventID = payload.eventIdentifier;
fetch('https://ourUrl.com/api/xm/1/events', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({id: eventID,status: 'TERMINATED'})
});
Comments
Please sign in to leave a comment.
File this one under, "figured it out as soon as I asked".
/** Terminate Initiating Event **/
var termRequest = http.request({
'endpoint': 'xMatters',
'method': 'POST',
'path': '/api/xm/1/events',
'headers': {'Content-Type': 'application/json'}
});
/** Set Up Request Body For Term **/
var termBody = JSON.stringify({id: eventID,status: 'TERMINATED'})
/** Term Event **/
var responseToo = termRequest.write(termBody);
console.log(responseToo.statusCode);
Sweet. Yep, that should do it. We're aware of the headache of needing two events for this kind of thing. I'll note that you are experiencing this as well and we'll get this sorted.
I'm curious though, would you mind sharing some details of what you are doing? I always love to hear what kinds of things people are cooking up in the field. And if you'd rather email me, that's fine too (tdepuy at xMatters.com)
Happy Wednesday!
--- Travis
Hi Travis. I am creating a notification and approval workflow of sorts for emergency code releases for our commercial and financial systems. It starts with a BA on the release management team submitting the aforementioned form with the details of the issue, what is planned and what areas are impacted. The outbound integration decides who should be notified based on the impacted area(s) and then calls the inbound integration to raise an event to request approval for the change from the area director(s). The BA monitors the responses and takes additional action depending on what responses they get.
Cool. I was going to suggest some additional script tweaking for the responses, but it sounds like that is a bit of a manual process to sort out what needs to happen next.
Glad you got it sorted out and thanks for sharing your use case.
Happy Wednesday!
I did come up with a related question. I added another Outbound integration to process responses. Is there a reference somewhere of the eventProperties[] that are included in the response? I would like to capture any comments that were included with the response to include in a notification back to the release management team.
{"recipient":"cjohns","device":"Work Email","response":"Approve","annotation":"null","eventIdentifier":908124000,"date":"18-04-04 19:49:42.327","eventProperties":[]}
That array is populated through the "Include in Outbound Integrations" checkbox on the layout of the form. See here for details:
https://help.xmatters.com/OnDemand/xmodwelcome/communicationplanbuilder/propertiescreating.htm#PropertySettings
Once you have the properties selected, they will show up in the right column when you're viewing the outbound integration script. This is helpful so you don't have to memorize the spelling of each.
Thanks Travis! I think some sample code would be tremendously helpful.
Ok, give this a whirl. This is on an outbound integration that fires on "Event Comments" and checks the event responses for a response called "Inform Stakeholders". We retrieve all the event responses and iterate through them and look for one that matches the "payload.author.targetName" from the Event Comment payload.
Where getEventResponses is:
Comments can come in from a variety of places and some have the response context (link in email, mobile) but some don't (via new API coming down the pipe, and in the event tracking report). I'm hoping the code above is a temporary situation and we can get the response sent with the "Event Comment" payload if it is known, but it might be a bit of time before we get there.
Oh, and I should also mention that the new sample scripts have some good information for working with comments. They don't have the above logic, but sometimes have good snippets to pilfer.
Let me know how that goes.
Happy Thursday!
--- Travis