最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - responseBody is not defined in Postman - Stack Overflow

programmeradmin8浏览0评论

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 not responseCode.code – rcshon Commented Apr 15, 2022 at 8:37
  • Thats don't work when i change data.code from responseCode.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 about pm.response.json()? – Danny Dainton Commented Apr 15, 2022 at 12:21
Add a ment  | 

1 Answer 1

Reset to default 6

The 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

发布评论

评论列表(0)

  1. 暂无评论