# Access token expiry

**URL:** <https://community.hubspot.com/t/access-token-expiry/15222>\
**Category:** APIs & Integrations\
**Tags:** oauth\
**Created:** [July 10, 2019, 7:28am UTC](https://community.hubspot.com/t/access-token-expiry/15222 "2019-07-10T07:28:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lybek76](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lybek76/32/31184_2.png) [@lybek76](https://community.hubspot.com/u/lybek76)\
**Post date:** [July 10, 2019, 7:28am UTC](https://community.hubspot.com/t/access-token-expiry/15222/1 "2019-07-10T07:28:46Z")

</div>

I have an integration in place and I’ve already implemented the programmatical refresh of the access token before the expiry time.  
However, i would like to add a safeguard in case this primary refreshing method fails.

That would rely on knowing the specific format of the response in case of any request that is executed with an expired access token - could you provide that please? I cannot find any information on it from docs.

One more question - is there a way to manually expire the access token (for testing purposes)?

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [July 10, 2019, 8:23am UTC](https://community.hubspot.com/t/access-token-expiry/15222/2 "2019-07-10T08:23:31Z")

</div>

Hello @lybek76

On making an API call with expired token, a status code 40X is returned with a proper response/error message that Access token is expired. Its not feasible to rely on specific format response. Instead you can make a check before every call if your access token in valid or not with the help of expires\_in parameter value that is returned while auth process.  
You can save expires\_in value as like current timeStamp + expires\_in into a DB record. And before making each call do a check if current timeStamp \> Saved value into DB, then refresh the access token else you can continue with same token.

Thanks

---

<div class="post-metadata">

**Author:** ![lybek76](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lybek76/32/31184_2.png) [@lybek76](https://community.hubspot.com/u/lybek76)\
**Post date:** [July 11, 2019, 5:36am UTC](https://community.hubspot.com/t/access-token-expiry/15222/3 "2019-07-11T05:36:42Z")

</div>

That’s exactly what I’m doing now, I just thought about creating a safeguard just in case something goes wrong with token refreshing.

You can never be too safe 😉

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [July 12, 2019, 8:34am UTC](https://community.hubspot.com/t/access-token-expiry/15222/4 "2019-07-12T08:34:15Z")

</div>

Hello,  
Yes either you can compare for expiry time or even more safe method will be to refresh token on when only few seconds left in expiry. This will never lead to any dead call with the access token expiry.  
Thanks

---

<div class="post-metadata">

**Author:** ![blainenye](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/blainenye/32/52876_2.png) [@blainenye](https://community.hubspot.com/u/blainenye)\
**Post date:** [December 17, 2019, 6:14pm UTC](https://community.hubspot.com/t/access-token-expiry/15222/5 "2019-12-17T18:14:43Z")

</div>

Thanks for the approach to refreshing the token.

Is there a way to force a token to expire for testing?

Blaine

---

<div class="post-metadata">

**Author:** ![lybek76](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/lybek76/32/31184_2.png) [@lybek76](https://community.hubspot.com/u/lybek76)\
**Post date:** [December 18, 2019, 1:39am UTC](https://community.hubspot.com/t/access-token-expiry/15222/6 "2019-12-18T01:39:16Z")

</div>

You can refresh your access token which will expire the old one automatically.

---

<div class="post-metadata">

**Author:** ![blainenye](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/blainenye/32/52876_2.png) [@blainenye](https://community.hubspot.com/u/blainenye)\
**Post date:** [December 18, 2019, 7:46am UTC](https://community.hubspot.com/t/access-token-expiry/15222/7 "2019-12-18T07:46:46Z")

</div>

Thanks Lybek, I was actually hoping to just be able to set the expiration time to 0 to test that case of handling an expired access token. I ended up just noting another expired token and testing with that.

Blaine

---

<div class="post-metadata">

**Author:** ![SGupta88](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SGupta88](https://community.hubspot.com/u/SGupta88)\
**Post date:** [December 6, 2023, 6:46am UTC](https://community.hubspot.com/t/access-token-expiry/15222/8 "2023-12-06T06:46:47Z")

</div>

Hey, I am in need to know that which API will regenerate the access token for me if my previous one got expired. I am checking its expiry by expires\_In but now i dont know which API to call to get a new access token. Can you please provide me with that endpoint and its details? Thanks

---

<div class="post-metadata">

**Author:** ![SGupta88](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SGupta88](https://community.hubspot.com/u/SGupta88)\
**Post date:** [December 6, 2023, 1:51pm UTC](https://community.hubspot.com/t/access-token-expiry/15222/9 "2023-12-06T13:51:39Z")

</div>

Hey, I am in need to know that which API will regenerate the access token for me if my previous one got expired. I am checking its expiry by expires\_In but now i dont know which API to call to get a new access token. Can you please provide me with that endpoint and its details? Thanks
