【发布时间】:2020-10-15 18:01:25
【问题描述】:
我的邮递员请求正文中有这些属性
{
"firstName": "QA",
"lastName": "Test {{agent_phone_number}}",
"email": "qatest-{{agent_phone_number}}@mail.com"
}
我正在尝试在“测试”选项卡上获取请求正文并将它们设置在集合变量中,代码如下所示
const requestJson = JSON.parse(pm.request.body.raw);
pm.collectionVariables.set('agent_firstName', requestJson.firstName);
pm.collectionVariables.set('agent_lastName', requestJson.lastName);
pm.collectionVariables.set('agent_email'. requestJson.email);
当我运行它时,我得到了这个错误
TypeError: Cannot read property 'email' of undefined
当我检查集合变量时,名字和姓氏被保存,但不是电子邮件..
“电子邮件”是否类似于 Postman 上的“保留”关键字?如果是这样,那么我如何从我的请求正文中获取“电子邮件”属性?
【问题讨论】:
标签: javascript postman postman-testcase