The postman can't see the collection response variables

hello,
I have a problem that I declared collection variables to retrieve the response code and text ((pm.response.code ) & (pm.response.text()) by test script. but after sending the request an error appears (ReferenceError: resp is not defined)


although it works good with header variables
thanks in advance

You have collection level variables that are pointing to pm.response.xxxx

pm.response is the response of a particular request, you can’t have this on a collection variable.

You have to set those variables using set or get.

pm.collectionVariables.set(“myVar”, pm.response.code);
console.log(pm.CollectionVariables.get("myVar"));

If you want to test against the response code, then you just need to put this in your test. Not sure why you would need to save this into a variable.

{pm.expect(pm.response.code).to.eql(400)}