# Rotate Adobe Experience Platform API via Postman

**URL:** <https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652>\
**Category:** Help Hub\
**Tags:** javascript, adobe\
**Created:** [March 9, 2025, 3:32pm UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652 "2025-03-09T15:32:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![telecoms-candidate11](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@telecoms-candidate11](https://community.postman.com/u/telecoms-candidate11)\
**Post date:** [March 9, 2025, 3:32pm UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652/1 "2025-03-09T15:32:56Z")

</div>

Adobe Experience Platform (AEP) uses OAuth 2.0 authentication, requiring a new access token every 60 minutes. How to keep API calls running smoothly, in automate token rotation in Postman.  
How to use JavaScript in Postman’s pre-request scripts to handle API key rotation.

---

<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:** [March 10, 2025, 9:54am UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652/2 "2025-03-10T09:54:12Z")

</div>

This is a reasonably complicated subject.

What have you researched so far?

There are a lot of topics on here that discuss this.

Some things to consider.

1. Have you tried the Postman Authentication helpers. These can be setup to automatically renew tokens within the clients (Desktop and web), but can’t be used for automated test suites through the Newman CLI or the new Postman Cloud CLI.

2. What type of OAuth authentication grant is being used. Only certain grant types like client credentials and password can be automated via scripting. If its using a grant type that requires user\browser interaction, then these cannot be fully automated (and is where the Authentication helpers come into play).

---

<div class="post-metadata">

**Author:** ![telecoms-candidate11](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@telecoms-candidate11](https://community.postman.com/u/telecoms-candidate11)\
**Post date:** [March 10, 2025, 11:52am UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652/3 "2025-03-10T11:52:36Z")

</div>

Hi Mike Jones, thanks for the hints, yes it is complicated, I am studying another options like Python Requests, I have searched around but no use case like it.

---

<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:** [March 10, 2025, 12:07pm UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652/4 "2025-03-10T12:07:31Z")

</div>

You haven’t mentioned the GRANT type being used.

That will dictate what options are available.

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [March 10, 2025, 4:24pm UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652/5 "2025-03-10T16:24:24Z")

</div>

I wrote [this blog post](https://community.postman.com/t/medium-article-how-to-automate-oauth2-token-renewal-in-postman/6630) a few years ago that uses pre-request scripts to renew OAuth tokens. Based on how the specific setup is of the Adobe Experience Platform, you might have to change a couple of things, but this is at least the skeleton to make things work.

---

<div class="post-metadata">

**Author:** ![telecoms-candidate11](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@telecoms-candidate11](https://community.postman.com/u/telecoms-candidate11)\
**Post date:** [March 11, 2025, 4:42pm UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652/6 "2025-03-11T16:42:05Z")

</div>

Hi Mike, actually are using client credentials. I will check Postman documentation helpers. Thank you very much for your time.

---

<div class="post-metadata">

**Author:** ![telecoms-candidate11](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@telecoms-candidate11](https://community.postman.com/u/telecoms-candidate11)\
**Post date:** [March 11, 2025, 4:46pm UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652/7 "2025-03-11T16:46:04Z")

</div>

Just to clarify:  
Adobe Experience Platform (AEP) uses OAuth 2.0 authentication, meaning access tokens expire every 60 minutes. To keep API calls running smoothly, how can I automate token rotation in Postman?

Specifically, how can I use JavaScript in Postman’s pre-request scripts to request a new token when needed and ensure all API calls use the latest token? Any best practices or examples would be helpful!

---

<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:** [March 12, 2025, 11:50am UTC](https://community.postman.com/t/rotate-adobe-experience-platform-api-via-postman/76652/8 "2025-03-12T11:50:20Z")

</div>

Client\_Credentials can be scripted.

Here is an example authenticating against Microsoft which checks the expiry for the token.

If the API doesn’t return the expiry date, then you will have to pull apart the token like in this example.

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

// console.log("currentDateTime: " + currentDateTime);
// console.log("tokenExpiry: " + tokenExpiry);
// console.log(pm.environment.get("bearerToken"));

if (!pm.environment.get("bearerToken") || currentDateTime > tokenExpiry) {
    pm.test("Pre-request check for Environment Variables", function () {
        let vars = ['client_id', 'scope', 'tenant_id', 'client_secret', 'scope'];
        vars.forEach(function (item) {
            // console.log(item);
            pm.expect(pm.environment.get(item), item + " variable not set").to.not.be.undefined;
            pm.expect(pm.environment.get(item), item + " variable not set").to.not.be.empty;
        });
        pm.sendRequest({
            url: 'https://login.microsoftonline.com/' + pm.environment.get("tenant_id") + '/oauth2/v2.0/token',
            method: 'POST',
            header: 'Content-Type: application/x-www-form-urlencoded',
            body: {
                mode: 'urlencoded',
                urlencoded: [
                    { key: "client_id", value: pm.environment.get("client_id"), disabled: false },
                    { key: "scope", value: pm.environment.get("scope"), disabled: false },
                    { key: "client_secret", value: pm.environment.get("client_secret"), disabled: false },
                    { key: "grant_type", value: "client_credentials", disabled: false },
                ]
            }
        }, function (err, res) {
            if (err) {
                console.log(err);
            } else {
                pm.test("Pre-request Microsoft login Status code is 200", () => {
                    pm.expect(res).to.have.status(200);
                    let resJson = res.json();
                    // console.log(resJson);
                    let token = resJson.access_token;
                    // console.log(token);

                    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);
                    // console.log(decoded);
                    let expiryDate = new Date(decoded.exp * 1000);
                    // console.log(expiryDate);

                    pm.environment.set("bearerToken", token);
                    pm.environment.set("bearerTokenExpiresOn", expiryDate);
                    // console.log("bearerTokenExpiresOn: " + pm.environment.get("bearerTokenExpiresOn"));
                });
            }
        });
    });
};

```
