Persisting (Global/Environment) Variables During Runtime

Just to clarify,

const requestOptions = {
   url: 'https://api.getpostman.com/environments/<environment_uid>',
   method: 'PUT',
   header: {
       'X-API-Key':'<your-API-key>'
   },
   body: {
       mode: 'raw',
       raw: JSON.stringify({
           'environment': {
           'name': 'New Env Name',
           'values': [
           {
            'key': 'var-one',
            'value': 'one'
           },
           {
            'key': 'var-two',
            'value': 'two'
           }]
           } 
           })
   }
}

pm.sendRequest(requestOptions, (error, response) => {
if (error) {
console.log(error)
}
})

The above request is used to update the Environment which you specify in the ‘url’ with the <environment_uid>.
Here: raw: JSON.stringify({ 'environment': { 'name': 'New Env Name',
If you set the environment name as ‘Globals’, it will update the environment with the name Globals, but the variables you set will be the environmnet variables and not global variables.

Ususally when you have Environment variables and you would like to update/persist them manually, you can use the above set of code, but for global variables I am not aware/sure if the same can be used to update and persist the global variables as they are seprate from environment variables.


More about variables scope here: https://learning.postman.com/docs/sending-requests/variables/#choosing-variable-scope

Sorry if i made it more complex for you.