First, you don't specify what HTTP action you are doing:
msg.http("https://xyz.pagerduty.com/api/v1/incidents/#{incident_key}/acknowledge")
Should end with .get()
or .post()
.
Also, possibly due to bad paste, your indentation if off a bit in the middle:
.post(string_query) (err, res, body) ->
result = JSON.parse(body)
if result.status == "success"
msg.send "Your log has been sent"
else
msg.send "There was an error sending your log."
Should be:
.post(string_query) (err, res, body) ->
result = JSON.parse(body)
if result.status == "success"
msg.send "Your log has been sent"
else
msg.send "There was an error sending your log."
Another thing, due to nature of NodeJS, these HTTP calls are made asynchronously, and there is a good chance that second call finishes before first one does. To avoid that, run the second request from callback of the first one:
msg
.http("https://events.pagerduty.com/generic/2010-04-15/create_event.json")
.headers
"Content-type": "application/json",
"Content-length": content_length
.post(string_query) (err, res, body) ->
result = JSON.parse(body)
if result.status == "success"
msg.send "Your log has been sent"
msg
.http("https://xyz.pagerduty.com/api/v1/incidents/#{incident_key}/acknowledge")
.get()
else
msg.send "There was an error sending your log."
You can find some examples of Hubot HTTP requests and other scripting tricks here.