I have JSON like below:
{
"success": true,
"code": 200,
"message": "Success",
"data": [
{
"ID_A": "AXCS-1-1",
"ID_B": "AXCS-1-1",
"Number": "11009988"
}
]
}
And my script for testing in postman:
var data = JSON.parse(responseBody);
if(responseCode.code === 200){
pm.environment.set("IdA",data.data[0].ID_A);
pm.environment.set("IdB",data.data[0].ID_B);
}
And I get the response:
How to fix this?
I have JSON like below:
{
"success": true,
"code": 200,
"message": "Success",
"data": [
{
"ID_A": "AXCS-1-1",
"ID_B": "AXCS-1-1",
"Number": "11009988"
}
]
}
And my script for testing in postman:
var data = JSON.parse(responseBody);
if(responseCode.code === 200){
pm.environment.set("IdA",data.data[0].ID_A);
pm.environment.set("IdB",data.data[0].ID_B);
}
And I get the response:
How to fix this?
Share Improve this question edited Apr 15, 2022 at 8:49 slhck 38.9k33 gold badges160 silver badges218 bronze badges asked Apr 15, 2022 at 8:11 DefandiDefandi 1241 gold badge1 silver badge6 bronze badges 3-
you have a typo:
data.code
notresponseCode.code
– rcshon Commented Apr 15, 2022 at 8:37 -
Thats don't work when i change
data.code
fromresponseCode.code
– Defandi Commented Apr 15, 2022 at 8:51 -
1
Just a general question, why have you used
JSON.parse(responseBody)
in the script? Have you followed a tutorial? Do you know aboutpm.response.json()
? – Danny Dainton Commented Apr 15, 2022 at 12:21
1 Answer
Reset to default 6The error says responseBody is not defined and the error is from prerequest script
responseBody is a global object that contains the response , this variable is available only in test script , and as pre-request is executed before the request is even send, requestBody variable wont be accessible