To retrieve new token once expired from automated java program

We are developing a standalone java batch process program in my company which read employee info from csv file to Create User account in Hipchat by calling Rest api. We need token to access Hipchat Rest api. So far I used personal access token which is hard coded in java file. As we are going to schedule this batch process, the new token need to be retrieved  or refreshed when the given token expires.

1) please let me know personal access token validity

2) As per my understanding token expiration time is one year

2) How to retrieve a token from my automated program once token is expired

Please suggest me how I can achieve this.


Thanks

Reji

1 answer

Hi Reji,

You are correct that personal tokens for the V2 HipChat API are valid for a period of 1 year before expiring. There is no way to refresh a personal token through the API.

Updating once every year manually may be sufficient for your purposes, if not the I would suggest instead creating an integration as you need access to the GROUP_ADMIN (we have some instructions available on the hipchat documentation).

Once you have an installed an integration generating a new access token is only a matter of calling the generate token method on HipChat's rest API. This should be called with your required scopes, a grant type of client credentials, and using basic auth with your oauth session / secret. These tokens last for an hour, so you would probably want to grab a new token each time you start an import (depending on how long these take / the time between).

curl -X "POST" "https://www.hipchat.com/v2/oauth/token" \
    -u OAUTH_ID:OAUTH_SECRET  \
    --data-urlencode "scope =GROUP_ADMIN" \
    --data-urlencode "grant_type =client_credentials "

One additional point if you decide to go down the integration route - once installed you wouldn't actually need to keep the integration running. You only need to save a copy of the OAuth ID + secret somewhere that you can use for your batched task. Please make sure you keep this information somewhere safe, as it would have admin access to your HC server.

Hope this information helps!

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Mar 26, 2018 in Hipchat Data Center

Migration of Hipchat server to Data Center - a retrospective

...able to use the clients After a bunch of testing (rooms, memberships, check for private message history, and most importantly - the custom emoticons!) nearly everything was looking as we needed, however...

455 views 2 6
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