HipChat Integration Plugin REST call

I need to make this REST call , that is provided from the HipChat integration plugin from my JIRA Plugin, specifically from the JAVA code:




In order to do that I wrote a Java class like so :


public class HCRoomCreate {
    private static final Logger log = Logger.getLogger(HCRoomCreate.class);
    private static String environment = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL);
    public static void createHipChatRoom(String issueKey) {
        String url = environment + "/rest/hipchat/compatibility/1.0/dedicatedroom";
        log.debug("URL configured for the REST Call is " + url);
        HttpClient httpClient = new HttpClient();
        String orig = "<username>:<password>";
        //encoding  byte array into  64
        byte[] encoded = Base64.encodeBase64(orig.getBytes());
        String sid  = new String(encoded);
       /* System.out.println("Original String: " + orig );*/
        System.out.println("Base64 Encoded String : " + new String(encoded));
        PostMethod post = new PostMethod(url);
        post.setRequestHeader("Content-Type", "application/json");
        post.setRequestHeader("Authorization", "Basic " + sid);
        //post.setRequestHeader("Authorization" ,"Bearer " + hipChatToken );
        //String payload = "{ \"name\": "+"\""+issueKey+"\"}";
        String payload = "{\n" +
                "                \"hipChatConfigured\": true,\n" +
                "                    \"projectKey\": \"<projectkey>\",\n" +
                "                    \"issueKey\": \""+issueKey+"\",\n" +
                "                    \"dedicatedRoom\": {\n" +
                "                        \"name\":  \""+issueKey+"\",\n" +
                "                        \"apiUrl\": \"https://<somevalidname>.hipchat.com\",\n" +
                "                        \"privateRoom\": false\n" +
                "                    },\n" +
                "                \"hipChatUserName\": {},\n" +
                "                \"canCreateRoom\": true,\n" +
                "                    \"canAssignRoom\": true,\n" +
                "                    \"connectionStatus\": \"CONNECTED\",\n" +
                "                    \"userCanAccessPrivateRoom\": false,\n" +
                "                    \"hipChatLoginUrl\": \"https://api.hipchat.com/sign_in\",\n" +
                "                    \"privateRoom\": false,\n" +
                "                    \"personalToken\": true,\n" +
                "                    \"jirauser\": true\n" +
                "            }";
        InputStream stream = new ByteArrayInputStream(payload.getBytes());
        //post.addParameter("name", issueKey);
        String responseBody = "";
        try {
            responseBody = post.getResponseBodyAsString();
        } catch (IOException e) {
            log.error("Fatal transport error " + e.getMessage());
        } finally {


But its giving me this error when this method call is invoked on issue creation:

 {"statusCode":403,"message":"You don't have enough permission or aren't logged in to HipChat to assign a dedicated room to this issue."}


The <username>/<password> in the above code is valid and I am able to login to JIRA with that, so technically since the HipChat integration plugin is already in the JIRA server, shouldnt the JIRA login credentials be enough?  Please advise.




1 answer

This widget could not be displayed.

Hi Yagnesh,

in order to be able to create a room inside HipChat a user needs HipChat's permission to do it. For example if you first click 'Create a [dedicated] room'  button in JIRA's interface we ask you to authorize against HipChat (using OAuth) and once we know that you are authorized we can create a room on your behalf.

You are getting a 403 response because the JIRA user you are making the call as has not yet been authorized against HC.

@Anatoli Kazatchkov , thanks for the reply. What I am trying to achieve is that when a user creates an jira ticket of a certain issuetype and certain severity, it should create a hipchat room on the fly with the name as the issue key. And also that room should be available under the "Dedicated Room" panel on the issue screen. Thats where I was leveraging the above mentioned dedicatedroom REST call , by calling it from the Java class I mentioned above. Do you know of a better way to acheive this?

Any updates @Anatoli Kazatchkov ? Please advise - I really need such kind of functionality in my plugin.

Yagnesh, it depends if you are writing a Connect add-on or if you are writing an old style add-on that runs within JIRA (i.e. P2). - For Connect add-ons you will need to prompt users to go through the OAuth Dance. You should do it inside your add-on UI, unfortunately there is no way to do it as a part of issue creation as far as I know. Once a user approved the access he/she would not need to do it again the next time. - If you are writing the old style P2 plugin you can access our API and use this methods to create dedicated room: UserService.getUser(String idOrEmail) RoomService.createRoom(String roomName, String ownerUserId, Option<String> topic, Option<Boolean> guestAccess, Option<String> privacy)

@Anatoli Kazatchkov , isnt there any proper way of authentication from the server side (Java) code itself so that I can make this call from the server side directly, using the code I provided?

Probably some additional parameters I can pass in the headers?

By the way, I am trying to make this call from a plugin written for a JIRA server, and not Cloud.

Yagnesh, the user on who's behalf you are making the call needs to log-in into HC. The user input is required if she hasn't authorised JIRA to act on her behalf yet.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Aug 10, 2018 in Hipchat

What should I think about when migrating HipChat to Slack?

...from the beginning. We have built up a lot of content in HipChat, with it being a core tool in our distributed company model. While it is true that we didn’t need to move to Slack immediately, we felt it...

247 views 1 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you