Undefined variable

I have a collection variable called artistId
i wanted to check whether in the response body the value of artistId matches the value of that variable
i think i did something wrong

i tried both of these:-

const response = pm.response.json();

pm.test(“Existing Artist Has Been Modified”, function(){
var artistId = pm.collectionVariables.get(“artistId”)
pm.expect.response.artistId.to.eql(artistId);

})

pm.test(“Existing Artist Has Been Modified”, function(){
pm.expect.response.artistId.to.eql(pm.collectionVariables.get(“artistId”))
})

and both gave me the same message:-
TypeError: Cannot read properties of undefined (reading ‘artistId’)

Calling variables the same name isn’t something that I would recommend as it can get messy with scope.

Call the stored artistID something like expectedArtistId

The define the responseArtistId something like…

var responseArtistId = response.ArtistId;

The test then comes a lot easier to work with.

pm.test(“Existing Artist Has Been Modified”, function(){
      pm.expect(response.ArtistId).to.eql(expectedArtistId); 
})

On face value though, your main problems is with this line.

pm.expect.response.artistId.to.eql(pm.collectionVariables.get(“artistId”))

Which should be…

pm.expect(response.artistId).to.eql(pm.collectionVariables.get(“artistId”))

thank u so much
wking gr8 now