Updating environment variables via postman API does not reflect on Postman UI

Kaustubh
Wed, 01 Oct 2025 05:16:01 +0000
Help Hub

I am trying to run a Newman runner on CI/CD. For that i need some environment variables to be updated during runtime like firebase_tokens and all.

In the CI/CD:

1. I am generating the required secrets.

2. Then updating the postman environment variables.

3. Then i run Newman runner.

The steps 1 and 3 are working as intended.
But the problem, is that the secrets that I am generating in the step 1 is not reflecting on the Postman UI as well as on the runner.

From what I can see in the Postman API docs,
The code to update the environment variables goes like this:

///////////////////////////
// POSTMAN
///////////////////////////

const postmanAPIKey = process.env.POSTMAN_API_KEY;
const environmentId = process.env.POSTMAN_ENVIRONMENT_ID;

if (!postmanAPIKey || !environmentId) {
  console.error("Missing POSTMAN_API_KEY or POSTMAN_ENVIRONMENT_ID");
  return;
}

const response = await fetch(
  `https://api.getpostman.com/environments/${environmentId}`,
  {
    method: "GET",
    headers: {
      "Content-Type": "application/json",
      "X-Api-Key": postmanAPIKey,
    },
  }
).catch((err) => {
  console.error("Failed to get environment", err.message);
  process.exit(1);
});

const data = await response.json();
const updatedEnvs = data.environment.values;

const updates = [{ key: "firebase_auth_token", value: token, enabled: true }];

for (const update of updates) {
  const existingEnv = updatedEnvs.find((env) => env.key === update.key);
  if (existingEnv) {
    existingEnv.value = update.value;
    existingEnv.enabled = true;
    existingEnv.type = existingEnv.type || "default"; // ensure type stays valid
  } else {
    updatedEnvs.push({
      key: update.key,
      value: update.value,
      enabled: true,
      type: "default",
    });
  }
}

console.log("updatedEnvs:", JSON.stringify(updatedEnvs, null, 2));

await fetch(`https://api.getpostman.com/environments/${environmentId}`, {
  method: "PUT",
  headers: {
    "Content-Type": "application/json",
    "X-Api-Key": postmanAPIKey,
  },
  body: JSON.stringify({
    environment: {
      id: data.environment.id,
      name: data.environment.name,
      values: updatedEnvs,
    },
  }),
}).catch((err) => {
  console.error("Failed to update environment", err.message);
  process.exit(1);
});

console.log("Environment updated successfully");

I also read the following post. I could also confirm i have all the env’s are shared in my environment file.

Some postman env variables not being used in github CI runs Help Hub

I have added a console log before the test and unfortunately the output is completely blank. I was hoping that would have given some clarity but sadly not. The full suite is working properly when run in the Postman UI, so I know for sure the variables are being called properly. Also confirmed in the Variables in request tab that I’m pulling down the correct value. I’ve manually looked through, but I’ll add a second console log at the very top of the suite to see if I can narrow things down.

1 post - 1 participant