1

I'm trying to create a notification for HipChat and unfortunately their HipChat-CS (https://github.com/KyleGobel/Hipchat-CS) nuget package doesn't work. So, I wanted to investigate how I could manually send a notification but their example is using cURL, which I'm unfamiliar with. I'd like to take their example and make it into something I can use with my c# application. Any help would be greatly appreciated! Here's the cURL example:

curl -d '{"color":"green","message":"My first notification (yey)","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' https://organization.hipchat.com/v2/room/2388080/notification?auth_token=authKeyHere

Thank you again!

AJ

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
AJ Tatum
  • 653
  • 2
  • 15
  • 35
  • 2
    "Doesn't work" isn't an error message. Instead of assuming that the package is broken, try to find out what is going wrong. Most likely it's the code that's broken, not the package. As for the example, it's a simple POST. You can execute a POST request with HttpClient. As for cURL's syntax - just look for the reference or run it on your command line. – Panagiotis Kanavos Jul 27 '16 at 16:30

2 Answers2

3

You can use an HttpWebRequest to establish the connection and send your json payload. You'll need to add System.Net to your using directives.

string jsonContent = "{\"color\":\"green\",\"message\":\"My first notification (yey)\",\"notify\":false,\"message_format\":\"text\"}";
byte[] jsonBytes = Encoding.ASCII.GetBytes(jsonContent);
var request = (HttpWebRequest) WebRequest.Create("https://organization.hipchat.com/v2/room/2388080/notification?auth_token=authKeyHere");
request.ContentType = "application/json";
request.Method = "POST";
request.ContentLength = jsonBytes.Length;

using (var reqStream = request.GetRequestStream())
{
    reqStream.Write(jsonBytes, 0, jsonBytes.Length);
    reqStream.Close();
}

 WebResponse response = request.GetResponse();
//access fields of response in order to get the response data you're looking for.
blackorchid
  • 377
  • 1
  • 15
1

To use HipChat-CS, I had to manually uninstall the automatically downloaded dependent package ServiceStack, and manually install a specific version, 4.0.56, of ServiceStack. Everything worked once I did this.

DWright
  • 9,258
  • 4
  • 36
  • 53