Missed Team ’24? Catch up on announcements here.

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

To retrieve new token once expired from automated java program

Reji
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 31, 2015

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

0 votes
Michael Oates
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 6, 2015

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
TAGS
AUG Leaders

Atlassian Community Events