Create a gist now

Instantly share code, notes, and snippets.

Embed
HipChat API v2 - Send a message to a room using cURL
#!/bin/bash
# Set the ROOM_ID & AUTH_TOKEN variables below.
# Further instructions at https://www.hipchat.com/docs/apiv2/auth
ROOM_ID=XXX
AUTH_TOKEN=XXX
MESSAGE="Hello world!"
curl -H "Content-Type: application/json" \
-X POST \
-d "{\"color\": \"purple\", \"message_format\": \"text\", \"message\": \"$MESSAGE\" }" \
https://api.hipchat.com/v2/room/$ROOM_ID/notification?auth_token=$AUTH_TOKEN
@juanmaflyer

This comment has been minimized.

Show comment
Hide comment
@juanmaflyer

juanmaflyer Apr 14, 2014

I had to change notification for message to make it work!

I had to change notification for message to make it work!

@danriti

This comment has been minimized.

Show comment
Hide comment
@danriti

danriti Apr 23, 2014

@juanmaflyer, thanks for the comment, I updated the gist!

Owner

danriti commented Apr 23, 2014

@juanmaflyer, thanks for the comment, I updated the gist!

@Jhloa2

This comment has been minimized.

Show comment
Hide comment
@Jhloa2

Jhloa2 Aug 5, 2014

Thanks so much for this!

Jhloa2 commented Aug 5, 2014

Thanks so much for this!

@gmcmillan

This comment has been minimized.

Show comment
Hide comment
@gmcmillan

gmcmillan Sep 4, 2014

If you want to send the token in the Auth header instead, you can do this:

curl -H "Content-type: application/json" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-X POST \
-d "{\"color\": \"purple\", \"message_format\": \"text\", \"message\": \"$MESSAGE\"}" \
https://api.hipchat.com/v2/room/$ROOM_ID/notification

If you want to send the token in the Auth header instead, you can do this:

curl -H "Content-type: application/json" \
-H "Authorization: Bearer $AUTH_TOKEN" \
-X POST \
-d "{\"color\": \"purple\", \"message_format\": \"text\", \"message\": \"$MESSAGE\"}" \
https://api.hipchat.com/v2/room/$ROOM_ID/notification
@DI-DaveGoodine

This comment has been minimized.

Show comment
Hide comment
@DI-DaveGoodine

DI-DaveGoodine Oct 10, 2014

Has anyone gotten this to work using a group notification token?

Has anyone gotten this to work using a group notification token?

@fizerkhan

This comment has been minimized.

Show comment
Hide comment
@fizerkhan

fizerkhan Nov 11, 2014

It does not work for me. It throws

{
  "error": {
    "code": 401,
    "message": "Authenticated requests only. See https://www.hipchat.com/docs/apiv2/auth for more information.",
    "type": "Unauthorized"
  }
}

It does not work for me. It throws

{
  "error": {
    "code": 401,
    "message": "Authenticated requests only. See https://www.hipchat.com/docs/apiv2/auth for more information.",
    "type": "Unauthorized"
  }
}
@dkarter

This comment has been minimized.

Show comment
Hide comment
@dkarter

dkarter Dec 8, 2014

It worked for me with personal auth token. Otherwise I was getting

{
  "error": {
    "code": 401,
    "message": "Invalid OAuth session",
    "type": "Unauthorized"
  }
}

any idea how to get it to work with a room notification token?

dkarter commented Dec 8, 2014

It worked for me with personal auth token. Otherwise I was getting

{
  "error": {
    "code": 401,
    "message": "Invalid OAuth session",
    "type": "Unauthorized"
  }
}

any idea how to get it to work with a room notification token?

@bvulaj

This comment has been minimized.

Show comment
Hide comment
@bvulaj

bvulaj Jan 14, 2015

If you generate a token for a specific room, this script works.

https://your-company.hipchat.com/rooms/tokens/XXXX

bvulaj commented Jan 14, 2015

If you generate a token for a specific room, this script works.

https://your-company.hipchat.com/rooms/tokens/XXXX

@henrikakselsen

This comment has been minimized.

Show comment
Hide comment
@henrikakselsen

henrikakselsen Jan 26, 2015

It's quite weird that it doesn't work with an admin token, isn't it?

It's quite weird that it doesn't work with an admin token, isn't it?

@buren

This comment has been minimized.

Show comment
Hide comment
@buren

buren Jan 26, 2015

This works for me..:

ROOM_ID=yourroomname
OWNER_ID=XXXYYYX
AUTH_TOKEN=XXXYYYXXX
MESSAGE="Hello world!"

curl --header "content-type: application/json" --header "Authorization: Bearer $AUTH_TOKEN" -X POST \
  -d "{\"name\":\"dev\",\"privacy\":\"private\",\"is_archived\":false,\"is_guest_accessible\":false,\"topic\":\"cURL\",\"message\":\"Message sent to HipChat from cURL\",\"color\":\"green\",\"owner\":{\"id\":$OWNER_ID}}" https://api.hipchat.com/v2/room/$ROOM_ID/notification

buren commented Jan 26, 2015

This works for me..:

ROOM_ID=yourroomname
OWNER_ID=XXXYYYX
AUTH_TOKEN=XXXYYYXXX
MESSAGE="Hello world!"

curl --header "content-type: application/json" --header "Authorization: Bearer $AUTH_TOKEN" -X POST \
  -d "{\"name\":\"dev\",\"privacy\":\"private\",\"is_archived\":false,\"is_guest_accessible\":false,\"topic\":\"cURL\",\"message\":\"Message sent to HipChat from cURL\",\"color\":\"green\",\"owner\":{\"id\":$OWNER_ID}}" https://api.hipchat.com/v2/room/$ROOM_ID/notification
@JesusCastellanos

This comment has been minimized.

Show comment
Hide comment
@JesusCastellanos

JesusCastellanos Apr 23, 2015

Also can't get Auth Token i keep getting the 401 code.

Anybody know how to get this token back correctly?

edit: @bvulaj was right. you can just generate a token by trying to go to:

https://your-company.hipchat.com/rooms/tokens/XXXX

cheers!

Also can't get Auth Token i keep getting the 401 code.

Anybody know how to get this token back correctly?

edit: @bvulaj was right. you can just generate a token by trying to go to:

https://your-company.hipchat.com/rooms/tokens/XXXX

cheers!

@josephfusco

This comment has been minimized.

Show comment
Hide comment
@josephfusco

josephfusco Jul 24, 2015

Would I be able to alert a hipchat room via analytics unique visitor?

Would I be able to alert a hipchat room via analytics unique visitor?

@saurabh-hirani

This comment has been minimized.

Show comment
Hide comment
@saurabh-hirani

saurabh-hirani Jul 29, 2015

Thanks for posting this - it's a useful example

Thanks for posting this - it's a useful example

@udomsak

This comment has been minimized.

Show comment
Hide comment
@udomsak

udomsak Aug 19, 2015

Thank you for sharing but i can't not follow your scripted.

udomsak commented Aug 19, 2015

Thank you for sharing but i can't not follow your scripted.

@regsmith

This comment has been minimized.

Show comment
Hide comment
@regsmith

regsmith Sep 8, 2015

Any luck sending attachments with curl?

regsmith commented Sep 8, 2015

Any luck sending attachments with curl?

@Richzendy

This comment has been minimized.

Show comment
Hide comment
@Richzendy

Richzendy Nov 4, 2015

Thanks a lot, works fine

Thanks a lot, works fine

@mihahribar

This comment has been minimized.

Show comment
Hide comment
@mihahribar

mihahribar Dec 18, 2015

Had to generate a token for that specific room, then it worked for me. 👍

Had to generate a token for that specific room, then it worked for me. 👍

@markcamos

This comment has been minimized.

Show comment
Hide comment
@markcamos

markcamos Feb 28, 2016

Thanks for posting this.

Works great using a room api ID. If the room name has an embedded "/" in it, it doesn't seem to work even if I URL encode the room name.

Thanks for posting this.

Works great using a room api ID. If the room name has an embedded "/" in it, it doesn't seem to work even if I URL encode the room name.

@ronjons

This comment has been minimized.

Show comment
Hide comment
@ronjons

ronjons Nov 28, 2017

What would be the syntax to send it to a single user: @username or @ALL in a room? Or is that not possible?

ronjons commented Nov 28, 2017

What would be the syntax to send it to a single user: @username or @ALL in a room? Or is that not possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment