Hipchat APIv2 Example: Send Room Notification

This is an example using Hipchat APIv2 to send a message to a room.

import json
import urllib2

token = "YOUR TOKEN"
header = {'content-type':'application/json'}

def send_message(room_id_or_name, message):
    url = "https://api.hipchat.com/v2/room/" +
            str(room_id_or_name) + "/notification"
    data = json.dumps({"message":message})
    req = urllib2.Request(url+"?auth_token="+token, data, header)
    res = urllib2.urlopen(req)
    return res.read()

if __name__ == '__main__':
    send_message(123456, "Hello, World!")

Leave a Reply

Your email address will not be published.

6 + 4 =