# How to get Expires\_in parameter in access token response

**URL:** <https://community.postman.com/t/how-to-get-expires-in-parameter-in-access-token-response/57419>\
**Category:** Help Hub\
**Tags:** access\_token, api\
**Created:** [February 7, 2024, 1:09pm UTC](https://community.postman.com/t/how-to-get-expires-in-parameter-in-access-token-response/57419 "2024-02-07T13:09:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![security-geologist-3](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@security-geologist-3](https://community.postman.com/u/security-geologist-3)\
**Post date:** [February 7, 2024, 1:09pm UTC](https://community.postman.com/t/how-to-get-expires-in-parameter-in-access-token-response/57419/1 "2024-02-07T13:09:59Z")

</div>

I was able to connect salesforce from postman and able to get _access token_, _Issued\_at_ parameter in response. But I am unable to see _expires\_in_ parameter. According to the [OAuth 2.0 spec](https://datatracker.ietf.org/doc/html/rfc6749#section-4.2.2) the `expires_in` parameter is included with the Access Token response and provides the lifetime of the returned token in seconds.  
Can someone help how do I get this parameter?

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [February 7, 2024, 1:44pm UTC](https://community.postman.com/t/how-to-get-expires-in-parameter-in-access-token-response/57419/2 "2024-02-07T13:44:44Z")

</div>

I have an API that doesn’t return the expiry in the response as its own key.

It is still contained in the token, but you will need to decode and extract it.

```auto
function parseJwt(token) {
    var base64Url = token.split('.')[1];
    var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
    var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join(''));

    return JSON.parse(jsonPayload);
}

let decoded = parseJwt(token);
let expiryDate = new Date(decoded.exp * 1000);

```

I also use moment to format the expiry date and the current date time so they are in the same format for calculations.

```auto
let moment = require('moment');
let currentDateTime = moment(new Date()).format("YYYYMMDDHHmmss");
let tokenExpiry = moment(pm.environment.get("tokenExpiresOn")).format("YYYYMMDDHHmmss");

```

You can then do something like…

```auto
if (!pm.environment.get("JWT") || currentDateTime > tokenExpiry) {
 // sendRequest to get new token.
}

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 8, 2024, 1:45pm UTC](https://community.postman.com/t/how-to-get-expires-in-parameter-in-access-token-response/57419/3 "2024-03-08T13:45:15Z")

</div>

Closed on March 8, 2024, 1:45pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
