Terminate an event from an integration

Not Yet Reviewed

Hey guys, 

Trying to terminate an event using code in an integration but running into an error, can you please advise; the code looks right to me :)

(The event is active at the time of this post)

 

Code
======
// Send the request to kill the path to the API
var terminate = '{ "status":"terminated" }';
var killevent = http.request({
"endpoint": "xMatters",
"path": pathtoevent,
"method": "PUT",
"body": terminate,
});
var response = killevent.write();
======

Response
======
> PUT https://<company>.<deployment>.xmatters.com/reapi/2015-01-01/events/293065 HTTP/1.1
> Accept: text/plain, application/json, application/*+json, /
> X-Trace: 882d3e8c-07e4-42e8-a27e-9175c3982f1b,59ef33a7-90d0-4d6d-a5bd-c37b0f3be952
> User-Agent: Xerus (EndpointClient)
> Content-Type: application/json; charset=utf-8
> Content-Length: 0


< HTTP/1.1 400 Bad Request
< Date: Sun, 11 Dec 2016 12:14:15 GMT
< Cache-Control: no-cache,no-store,max-age=0
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Content-Type: text/plain
< Via: 1.1 xmatters
< Vary: Accept-Encoding
< X-FRAME-OPTIONS: SAMEORIGIN
< Strict-Transport-Security: max-age=3600; includeSubDomains; preload
< X-Robots-Tag: noindex
{"type":"DATA_FORMAT_ERROR","message":"Request data is malformed and cannot be parsed.","errorDetails":[{"jsonPath":"$","details":"com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input\n at [Source: [B@5e6ca2a0; line: 1, column: 1]"}]}
======

Used the following as a reference point: https://help.xmatters.com/OnDemand/xmodwelcome/communicationplanbuilder/appendixrestapi.htm?cshid=apiPUTevent#PUTevent

Any help is greatly appreciated... Thanks!

0

Comments

5 comments
Date Votes

Please sign in to leave a comment.

  • Hey George!

       Pretty close. Try this:

    var terminate = '{ "status":"terminated" }';
    var killevent = http.request({
    "endpoint": "xMatters",
    "path": pathtoevent,
    "method": "PUT",
    "headers": {
    "Content-Type": "application/json"
    }
    });

    var response = killevent.write( terminate );

    The `status` needs to be sent as the body of the HTTP request, which is done by passing as a parameter to the `write` method. Also you'll need the Content-type header to specify a JSON payload. 

    Doc here

     EDIT: Also note that your payload can be passed as either JSON or a string. So you could do this also:

    var terminate = { "status":"terminated" };
    0
  • Hey Travis,

    Thanks for the response! works perfectly... although logs still show a 400 Bad Request (but we aren't complaining, this solves a quirk with the way we use the tool so thanks again :)

     

    0
  • Good to hear! 400 is generally a badly formed payload. If you want some help, post the details here and we can take a look.

     

    0
  • Hey Travis,

    Turned out we were trying to kill the same event again (copied and pasted your code above) so the 400 was due to the event not being active... removed old part and now all working :)

    Thanks again

    0
  • Ah, yep, that'll do it!

    Good to hear. 

    0

Didn't find what you were looking for?

New post