Error recognizing variables

Solved
I was able to solve this by changing the pm.env.get() to pm.variable.get and not it just works. Hope this helps anyone else but also I feel like it should be fixed.

Hi,

I’m attempting to setup a pm.sendrequest() in the pre-request script section, of the first request of a collection. The intention of this, is to refresh our Auth token, if necessary.

I have 2 environment variables clientId & clientSecret.

When I attempt to send the request it’s throwing a TypeError:

TypeError cannot read property ‘get’ of undefined

It doesn’t seem to recognize the data from the 2 environment variables within the body of the request.

This is how the request is being formatted:

There are back ticks around the url but are not being displayed below.

const echoPostRequest = {
   url: `${pm.environment.get('apimBaseUrl')}/identity/connect/token`,
  method: 'POST',
  header:{
      'Content-Type':'application/x-www-form-urlencoded'
      },
  body: {
    mode: 'urlencoded',
    urlencoded:[
          {key:'client_id', value: '`${pm.enviroment.get('authSrvClientId')}`'},
           {key:'client_secret',value:pm.enviroment.get('authSrvClientSecret')},
        ]
    }
  };

As you can see I’ve attempted to call these in 2 different manners but neither seems to works.

Note The url that’s being requested does work.

Does anyone have a suggestion on why Postman isn’t okay with these environment variables?

They both have value and are set prior to this request being kicked off. Note that the intellisense does auto fill those value when I start typing them.

This is a guide I was attempting to follow, if that helps:
https://dannydainton.com/2018/09/10/postman-the-bearer-of-good-news/

Wanted to also point out that I attempted to call .toString() on both the client and secret variables but this was also unsuccessful.

Trying console.log(typeof pm.environment.get(‘authSrvClientId’)); returned string.
Also logging the variable into console does return the value. So this appears to be something related to trying to call those variables within the urlencoded body.

This should be environment on both the variables - that’s the reason for the error, from what I can see.

Also the way you are referencing the second of the 2 variables is incorrect JavaScript syntax.

My script can be found here: