Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There was an error in evaluating the Pre-request Script

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?

like image 637
code-8 Avatar asked Jan 24 '18 18:01

code-8


2 Answers

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.

like image 61
Clint Avatar answered Sep 16 '22 11:09

Clint


In my case, there was a script that was screwing up my request. If you get the postman collection from someone else, check this and try to fix it. (in my case I don't need it so I deleted it)

enter image description here

like image 30
mattylantz Avatar answered Sep 17 '22 11:09

mattylantz