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

JIRA Hipchat integration plugin's REST call fails when called from some other plugin

Yagnesh Bhat
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.
November 16, 2015

The JIRA HipChat integration plugin has this REST call which I am unable to invoke successfully from my plugin:

 

AJS.params.baseURL + "/rest/hipchat/compatibility/1.0/issuepanel/data/"+issueId+".json

 

This call can give me the parts of the HipChat Room URL I am looking for , and if I make it from REST Browser, or even if I paste this in the address bar of my browser, it still gives me the JSON. But I need to make this call from my plugin , and in that case it always errors out i.e. goes to the error: section of the AJAX call. Please provide your input on this - is there any restrcition in making that REST call from any other plugin?

 

Code wise, I am basically calling this function I created:

 

function getHipChatRoomURL(issueId) {
    console.log("Invoking get hipchat room URL");
    var hipChatRoomURL = "";
    var urlToGetHipchatRoom =  AJS.params.baseURL + "/rest/hipchat/compatibility/1.0/issuepanel/data/"+issueId+".json";
    console.log("Attempting to get the hipchat room URL thru this REST Call " + urlToGetHipchatRoom);
    AJS.$.ajax({
        url: AJS.params.baseURL + "/rest/hipchat/compatibility/1.0/issuepanel/data/"+issueId+".json",
        dataType: "application/json",
        async:false,
        success: function(response) {
            var apiUrl = response.dedicatedRoom.apiUrl;
            var roomId = response.dedicatedRoom.roomId;
            hipChatRoomURL = apiUrl+"/chat/room/"+roomId;
            hipChatRoomURL = "<a href="+"\'"+ hipChatRoomURL+"\'"+">Join Hipchat Room</a>";
            console.log("Hipchat room URL In AJAX Call is " + hipChatRoomURL);
            return hipChatRoomURL;
        },
        error: function() {
            hipChatRoomURL = "No Hipchat room configured for this issue";
            return hipChatRoomURL;
        }
    });
    console.log("Get hipchat room URL invoked");
    return hipChatRoomURL;
}

 

And invoking this method like this under AJS.toInit() :

setTimeout(function() {
     var issueKey = AJS.Meta.get("issue-key");
     AJS.log("ISSUE KEY SENT to find the room URL is " + issueKey)
     hipChatRoomURL = getHipChatRoomURL(issueKey);
     console.log("Hipchat room URL is " + hipChatRoomURL);
 },1000);

 

But I am seeing that it always executes the error: section of the AJAX call above and returns "

No Hipchat room configured for this issue"

 

Please advise as soon as possible.

 

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Carlos Khatchikian
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 14, 2016
var issueKey = AJS.Meta.get("issue-key");
if (issueKey) {
 return AJS.$.ajax({
        url: AJS.contextPath() + "/rest/hipchat/integrations/1.0/issuepanel/data/" + issueKey,
 cache: false,
 dataType: 'json',
 type: "GET"
 }).done(function (data) {

// You get the data here
 }).fail(function (jqXHR, textStatus) {
    // Here the failing thing
 }).always(function() {
    
 });

 

Enjoy!
0 votes
Carlos Khatchikian
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 16, 2015

The REST url is: 

AJS.params.baseUrl + "/rest/hipchat/integrations/1.0/issuepanel/data/" + issueId

There is no ".json" in the end.

0 votes
Volodymyr Krupach
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.
November 16, 2015

Never worked with HipChat REST but have a feeling that your REST call needs authentication. Calls from REST browser or direct calls from browser already have authentication cookies.

Yagnesh Bhat
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 14, 2016

@Volodymyr Krupach , what kind of authentication would be needed if I have to make that call from the server side Java code, such that it shows the same behavior as the REST API Browser? In general, lets say one JIRA plugin has some REST calls and I need to call those from SERVER side (a.k.a, from Java code), could you please advise on how should I go about taking care of authentication? It will also help if u have some code snippet to guide

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events