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/