0

I am using PerfectSwift for a RESTful API to bridge our TeamCity build server and HipChat; however I am stuck at a point whereby I am unable to post to the HipChat backend using Perfect's cURL wrapper.

The command I am trying to mimic is:

curl -d '{"color":"green","message":"My first notification (yey)","notify":false,"message_format":"text"}' -H 'Content-Type: application/json' https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>

I currently have the following code in my Perfect program:

let curl = CURL(url: "https://<MY DOMAIN>/v2/room/509/notification?auth_token=<MY AUTH TOKEN>")
curl.setOption(CURLOPT_POST, int: 1)
curl.setOption(CURLOPT_POSTFIELDS, s: "{\"color\":\"green\",\"message\":\"My first notification (yey)\",\"notify\":false,\"message_format\":\"text\"}")
curl.setOption(CURLOPT_HTTPHEADER, s: "[Content-Type:application/json]")
curl.perform { (code, header, body) in

}

However, the message never gets to HipChat, or, if it does, it's not in a readable format.

When I paste the first command into terminal, everything works as expected.

From my understanding, this uses a similar system to PHP, and I am therefore including the PHP tag as I feel PHP developers may be able to offer advice if I am using the wrong CURLOPTs etc...

Thanks in advance.

Jacob King
  • 6,025
  • 4
  • 27
  • 45

0 Answers0