Javascript – There was an error in evaluating the Pre-request Script

javascriptjsonpostman

I'm trying to access the response of my POST request in Postman via Post Request Script.

I added this 2 lines, under Pre-request Script

let response = pm.response.json(); 
console.log('JSON Response: ',response );

Then, I opened up my Postman console, before hit Send to make my POST request

I kept getting

There was an error in evaluating the Pre-request Script: TypeError: Cannot read property 'json' of undefined

Do I need to enable anything on Postman?

Best Answer

Pre-request scripts are ran before the request is sent. You do not have a response yet.

Try putting your script under the Tests tab, which is ran after a response is received.

Related Topic