It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

I have som problems getting HC to work from groovy. No problems fro Powershell or curl:

 

curl -s -d "https://api.hipchat.com/v1/rooms/message?auth_token=xxxxxxxxxxxx?room_id=Operations&from=JIRA&message=Issue+Classified+as+Splunk+%20+https://jira.netic.dk/browse/TEST-410&color=green"

 

Works fine.

 

curl -s https://api.hipchat.com/v2/room?auth_token=xxxxxxxx&auth_test=true
[1] 10432
root@docs02:/pack/jira-data/scripts/com/netic/listener# {
"error": {
"code": 401,
"message": "Invalid OAuth session",
"type": "Unauthorized"
}
}^C

 

Groovy - I have tried a lot of variants, like:

 

//Fire HipChat message
String requestMethod="POST"
String baseURL="https://api.hipchat.com/v1/rooms/message?auth_token=xxxxxxx"
//String baseURL="https://api.hipchat.com/v2/room?auth_token=7xxxxxxx&auth_test=true"

def url = new java.net.URL(baseURL);
URLConnection connection = url.openConnection();
connection.setRequestMethod(requestMethod);
connection.doOutput = true
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type", "text/plain");

OutputStreamWriter out = new OutputStreamWriter(
connection.getOutputStream());
out.write("room_id=Operations");
out.write("from=JIRA");
out.write("message=Issue");
out.write("color=green");
out.close();

 

In general, all I get is either 400 or 401 . ...

 

Anyone with a functioning script?

1 answer

1 accepted

0 votes
Answer accepted

Hi Normann,

I haven't personally used Groovy but it sounds like there may be an issue with the tokens that you're using, given the authentication errors you're getting. Note that there are two APIs available, v1 and v2 (the former being deprecated for a while now).

On your cURL example you're calling APIv1, and on the second example you're calling APIv2, so you'll want to make sure the tokens match each request. APIv1 tokens can be generated at https://hipchat.com/admin/api , while for v2, you can create a personal access token at https://hipchat.com/account/api

More info can be found at https://developer.atlassian.com/hipchat/guide/hipchat-rest-api/api-access-tokens

Thanks, I was not aware that the V2 token was different from V1 - but I am aware of the "Note that there are two APIs available, v1 and v2 (the former being deprecated for a while now)."

 

I will look into it and reply back.

 

BR,

 

Normann

Indeed, that was the key to getting forward :-)

 

Thanks !!

 

BR,

 

Normann

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Hipchat

Hipchat Cloud and Stride have reached End of Life (updated)

All good things come to an end - thanks to all our customers and partners who have been along the Hipchat and Stride journey with us.  As of Feb 15th 2019, Hipchat Cloud and Stride have reached ...

35,225 views 9 8
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you