# Deprecated warning in the Postman Console

**URL:** <https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476>\
**Category:** Help Hub\
**Tags:** console, scripts, setnextrequest\
**Created:** [July 23, 2024, 1:20pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476 "2024-07-23T13:20:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [July 23, 2024, 1:20pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/1 "2024-07-23T13:20:26Z")

</div>

I’m starting getting the Warning in the Console

**“Using “postman.setNextRequest” is deprecated. Use “pm.execution.setNextRequest()” instead.”**

But it doesn’t look like I use **postman.setNextRequest** command in Scripts code.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 23, 2024, 1:24pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/2 "2024-07-23T13:24:59Z")

</div>

Hey @osiuser 👋

Could you provide more details about the script that you have where you’re seeing this in the console?

---

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [July 23, 2024, 2:36pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/3 "2024-07-23T14:36:00Z")

</div>

```auto
async function getExternalAccountId(account_id, i) {
    //Get the external_account_Id
    await pm.sendRequest({
        url: pm.environment.get("baseUrl") + '/restapi/v2.1/accounts/' + account_id,
        method: 'GET',
        header: {
            "User-Agent": "PostmanRuntime",
            "Connection": "keep-alive",
            "Authorization": "Bearer " + pm.environment.get("accessToken")
        },
        //body: { }
    }, async function (err, res) {
        if (err) {
            console.log(err);
        } else {
            var jsonAccountData = res.json();
            var s = (i == 0) ? '' : ('_' + i);
            await postman.setEnvironmentVariable("externalAccountId" + s, jsonAccountData.externalAccountId);
            //await console.log("externalAccountId" + s, jsonAccountData.externalAccountId);
        }
    }
    );
}

async function processResponseBody(responseBody) {

    var jsonData = JSON.parse(responseBody);
    var accounts = jsonData.accounts;
    if (jsonData.hasOwnProperty("sub")) {
        await postman.setEnvironmentVariable("userId", jsonData.sub);
    }

    await postman.setEnvironmentVariable("email", jsonData.email);

    for (var i = 0; i < accounts.length; i++) {
        if (accounts[i].hasOwnProperty("is_default")) {
            if (accounts[i].is_default === true) {
                if (accounts[i].hasOwnProperty("organization")) {
                    await postman.setEnvironmentVariable("organizationId", accounts[i].organization.organization_id);
                }
                await postman.setEnvironmentVariable("baseUrl", accounts[i].base_uri);
                await postman.setEnvironmentVariable("accountId", accounts[i].account_id);

                await postman.setEnvironmentVariable("externalAccountId", '');
                //Get the external_account_Id
                await getExternalAccountId(accounts[i].account_id, 0);

                await postman.setEnvironmentVariable("accountName", accounts[i].account_name);

                //console.log("Default", i, accounts[i].account_name, jsonAccountData.externalAccountId)

            }
        }

        await postman.setEnvironmentVariable("accountId" + '_' + (i + 1), accounts[i].account_id);

        await postman.setEnvironmentVariable("externalAccountId" + '_' + (i + 1), '');
        await getExternalAccountId(accounts[i].account_id, i + 1);

        await postman.setEnvironmentVariable("accountName" + '_' + (i + 1), accounts[i].account_name);
        await postman.setEnvironmentVariable("accountId_isDefault" + '_' + (i + 1), accounts[i].is_default);

        //await console.log(i, accounts[i].account_name);
    }
}

// Main function
//Get Authorization header value and save it in the var
let token=pm.request.headers.get('Authorization');
pm.environment.set("accessToken", token.replace('Bearer ',''));

postman.clearEnvironmentVariable("userId");
postman.clearEnvironmentVariable("email");
postman.clearEnvironmentVariable("accountId");
postman.clearEnvironmentVariable("externalAccountId");
postman.clearEnvironmentVariable("baseUrl");
postman.clearEnvironmentVariable("accountName");
postman.clearEnvironmentVariable("organizationId");
postman.clearEnvironmentVariable("organizationName");

var i = 1;
while (pm.environment.has('accountId' + '_' + i)) {
    postman.clearEnvironmentVariable("accountId" + '_' + i);
    postman.clearEnvironmentVariable("externalAccountId" + '_' + i);
    postman.clearEnvironmentVariable("accountId_isDefault" + '_' + i);
    postman.clearEnvironmentVariable("accountName" + '_' + i);
    i++
};

processResponseBody(responseBody);

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 23, 2024, 2:48pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/4 "2024-07-23T14:48:48Z")

</div>

There are many places that your would need to change the script which don’t relate to the error message.

```auto
// Old
postman.setEnvironmentVariable()

// New
pm.environment.set()

```

```auto
// Old
postman.clearEnvironmentVariable("userId")

// New
pm.environment.unset("userId")

```

It would be interesting to see if changing those, should the `setNextRequest` message in the console?

---

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [July 23, 2024, 3:18pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/5 "2024-07-23T15:18:01Z")

</div>

I’ve made the suggested changes.

There is no warning now, but the new code removed a lot variables in the Environment.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 23, 2024, 3:20pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/6 "2024-07-23T15:20:24Z")

</div>

That’s completely my bad 😢

I should have said `.unset()` and not `clear()` - I apologise if that’s messed things up for you.

---

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [July 23, 2024, 3:28pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/7 "2024-07-23T15:28:07Z")

</div>

My understanding was “unset” set value to Null, while "clear"removes the variable. I used “clear” in the code to remove a specific vars.

Why were other vars that were not used in the code removed?

Update:  
I’ve just tested and can confirm that both **postman.setEnvironmentVariable** and **postman.clearEnvironmentVariable** cause the Warning to appear

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [July 23, 2024, 4:24pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/8 "2024-07-23T16:24:58Z")

</div>

Using the `.unset('var_name')` would remove that variable but `.clear()` would remove all the variables in that scope.

> To remove a variable from the active environment, specifying the variable by name:
> 
> - `pm.environment.unset(variableName:String):function`
> 
> To clear all variables in the active environment:
> 
> - `pm.environment.clear():function`

I’ve also used a function in the past to clear out specific variables that start with a certain prefix, might not work in your context but worth sharing:

```auto
function cleanupEnvVars(prefix) {
    const clean = Object.keys(pm.environment.toObject())
    clean.forEach((arrItem) => {
        if (arrItem.startsWith(prefix)) {
            pm.environment.unset(arrItem)
        }
    })
}

cleanupEnvVars('test_');

```

That could also be added to the Package Library and used anywhere, could even be amended to point to any of the scopes.

---

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [July 23, 2024, 4:36pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/9 "2024-07-23T16:36:19Z")

</div>

Thanks Danny. It helps.

---

<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:** [August 22, 2024, 4:36pm UTC](https://community.postman.com/t/deprecated-warning-in-the-postman-console/64476/10 "2024-08-22T16:36:54Z")

</div>

Closed on August 22, 2024, 4:36pm UTC

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