Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to use HipChat Put APIs

Jackson Farnsworth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2019

I'm trying to clean up my HipChat instance in preparation for our move to Slack, one such job is cleaning up room names.

I've found the API for updating a room here, and have grabbed my user auth_token from the "/account/api" page as well with the scope "Administer Room".

From here, I'm using python to run the command, as there's a number of rooms I need to update the name of, my code is as follows for just one room:

import requests, json

URL = "https://api.hipchat.com/v2/room/myRoomId"

PARAMS = {'auth_token': "myAdministerRoomToken",
"name" : "New Room Name Here"}

r = requests.put(url=URL, data=PARAMS)

print(json.dumps(r.json(), sort_keys=True, indent=4)) 

 However, I get the following response:

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

The page linked to in the error code doesn't seem that enlightening, or maybe I'm just dense. (Likely option #2)

I've also tried adding all the required parameters as marked by the API, but I still get the same response. Any ideas what I'm missing?

1 answer

1 accepted

1 vote
Answer accepted
AhmadDanial
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 31, 2019

Hi, @Jackson Farnsworth

My suspicion for now is that you might not have the credentials to perform the action on rooms that you are not an owner / admin of. The logic behind this is that if anyone participants have the ability to do this, room information can change at any time just by having a user creating an API v2 token with the required scope (admin_room) and firing the API call with the parameters. For example, private rooms changed to public which can compromise information. So, let us take one step at a time here.

As of now, can you please confirm if there are any rooms that you own / administer in the group? If yes, let us try to update the room first and verify if the changes gets reflected properly.

Once that is done, try to perform the same update on another room which you are not an admin / owner to confirm the theory. Please let me know how it goes on your end.

Jackson Farnsworth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2019

I changed the Room ownership to myself, and re-ran the API call, but it still failed with the same error.

Just to be sure, I created a room myself and ran the call, still the same error.

AhmadDanial
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 4, 2019

Hi, @Jackson Farnsworth

I went ahead and tested this on my end and verified that it works with a single room API v2 update:

Check the room name before the update (Private)

Ahmad-Danials-MacBook-Pro:~ ahmaddanialmohammad$ curl -H "Content-Type: application/json" -X GET https://api.hipchat.com/v2/room/4844759?auth_token=<token> | python -m json.tool | jq '. | {name}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1006 100 1006 0 0 782 0 0:00:01 0:00:01 --:--:-- 782
{
"name": "Private"
}

Ran the API to update the room with the required properties:

Ahmad-Danials-MacBook-Pro:~ ahmaddanialmohammad$ curl -H "Content-Type: application/json" -X PUT -d "{\"name\": \"Public_2\", \"privacy\": \"private\", \"is_archived\": false, \"is_guest_accessible\" : false, \"topic\":\"This is a new topic\", \"owner\": {\"id\": 898203}}" https://api.hipchat.com/v2/room/4844759?auth_token=<token>

Verified that the room name is updated to (Public_2)

Ahmad-Danials-MacBook-Pro:~ ahmaddanialmohammad$ curl -H "Content-Type: application/json" -X GET https://api.hipchat.com/v2/room/4844759?auth_token=atjT5Rui4zdxNeu7EgLfxojQAiv8jVLa2TMBLHAy | python -m json.tool | jq '. | {name}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1049 100 1049 0 0 935 0 0:00:01 0:00:01 --:--:-- 935
{
"name": "Public_2"
}

In this case, I used the API v2 token with the following scope:

Screenshot 2019-02-05 at 08.40.53.png

Can you try to update a single room's name first before attempting it on several rooms using the script?

Jackson Farnsworth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2019

I have been testing this on just one room until I can get it working.
I've tried your API call with a copy and paste, then replacing the room id, owner id, and auth token to match mine, but I still get that authentication error.

AhmadDanial
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 5, 2019

Hi, @Jackson Farnsworth

Understood. It is a strange behavior indeed. Let us try to tackle this from another perspective. May I know if you are able to generate a new token with the Manage Room and Administer Room scope and test again?

Additionally, can you please provide me with the screen shot on how you have this tested on your end? Do you just make that single line API call through your CLI / terminal or another tool such as POSTMAN? Thanks.

Jackson Farnsworth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2019

Sorry, I messed up your cURL when copy and pasting (overwrote the owner value with just the ID number, not "{id : #####}". It works now.

Apparently Python for the PUT command will bug out when the auth_token in in the parameters variable, but work fine when appended to the URL. Don't know why, but it works now.

All in all, thanks for your help! 

AhmadDanial
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 6, 2019

No worries, @Jackson Farnsworth. More than happy to help!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events