Hi everyone,
I’m a newbie that is slowly finding my feet with postman, I’m not good with code either (which sucks but something for me to work on in time) - hoping to do some of the postman courses mentioned above (when time permits). Please forgive me if I use the wrong terminology here.
In the meantime I am wondering if anybody could explain to me in very simple terms where I am going wrong, I have tried some of the varying examples in this thread, but can’t seem to get the key I want to write out to a variable.
I am trying to access the data that is returned in the response body from a basic get request.
Response
In the Test section of GET Request, I am wanting to validate the ‘mPP’ is what I expect it to be, to I can ensure that this value is what I need it to be with a post request prior to running the GET.
I added some snippets where I can search for the value using the below, but it feels clunky.
’ pm.test(“Check Value is correct 4.88”, function () {
** pm.expect(pm.response.text()).to.include(“4.88”);**
});’
I am now trying to do this using the below, but I get an error.
‘let responseData = pm.response.json();
console.log(responseData);
pm.environment.set(“mPP”, responseData.hotels[1].mPP[0]);’
I get this response data, and I am wanting to access the mPP value in yellow, but trying the above and variations, no what I do, I can seem to get it set grab the value and set the env variable and get varying errors depending on what I try e.g.,
TypeError: Cannot read properties of undefined (reading ‘mPP’)
Hope I have explained this well enough.
As I say I will look at the postman learning stuff when time permits for me to go through it all.
Thank you in advance for any help that may be offered to me.