I am trying to confirm the functionality of POST requests to a hardware device. To do this I want to get the current state of the hardware first by using a GET requests in the “Pre-requests Script” section.
My code in there is:
pm.sendRequest("http://192.168.20.150:8080/picsetup", function (err, response) {
const GETpreRequest = pm.response,json();
});
Which gives me the error: “TypeError: Cannot read properties of undefined (reading ‘json’)”
When I look at the type for pm.response it shows it as undefined, but looking in the console the response bogy looks to be correctly formatted json.
GET http://192.168.20.150:8080/picsetup
200
17 ms
Network
Request Headers
User-Agent: PostmanRuntime/7.36.3
Accept: */*
Postman-Token: 47352790-0aed-4dc8-910d-d2dcfa859a71
Host: 192.168.20.150:8080
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Response Headers
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Wed, 28 Feb 2024 08:09:16 GMT
Content-Length: 279
Response Body
{"Flip":"Off","Mirror":"Off","Effect":"Off","WDREnable":"Off","WideDynamicRange":"0","Gamma":"0","BackLightCom":"Off","DeFlicker":"1","Portrait":"Off","Brightness":"50","Color":"50","Hue":"50","HighlightComp":"Off","Contrast":"50","Sharpness":"50","TWODNR":"20","ThreeDNR":"30"}↵
concole.log of pm.responce gives me: undefined
POST http://192.168.20.150:8080/picsetup
When I use similar code in the “Tests” section of this POST request I get the response I would expect.
I am new to javaScript, and scripting in Postman, so I may have missed something obvious. If somebody could tell me why I can’t access the json in the response body (or if there is a better method of doing it) that would be fantastic.
Thanks,
DaveK