[英]In Postman, how do I take a response body from a Get Request, and put it in a PUT request with minor changes
我已执行POST请求以创建新合同。 此请求的Json响应是字符串ID。
"03007"
我的发布请求具有将响应另存为环境变量的测试。
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("newContractNb", jsonData);
然后,我有一个GET请求,将响应变量插入到请求中,以便获取我创建的合同的数据。
我的回应就是这样。
{
"contractNb": "03007",
"progSrvcNm": "009",
"contractPrtyNm": "PostmanAutomationContract",
"contractCd": "000",
"signDt": "2018-01-01T00:00:00",
"startDt": "2018-01-01T00:00:00",
"endDt": "2025-01-01T00:00:00",
"remitTerms": 30
}
我在Get方法中有一个Test来将该响应主体保存为变量。
pm.environment.set('getRequestBody', pm.response.json())
然后可以在PUT请求的“正文”或“先决条件”部分中使用此变量,但是以某种方式使其能够更改选择参数(例如,仅限contractPrtyNm)吗?
当您收到来自“ {{url}} / {{newContractNb}}”的回复时,您可以尝试这样的操作。 修改属性,然后在请求中设置主体:
var jsonData = pm.response.json();
jsonData.progSrvcNm = "blah";
pm.environment.set("response_b", jsonData);
然后在您的PUT请求(类型无关紧要)中,将其设置为
pm.environment.get("response_b");
感谢@Danny Dainton的帮助!
帖子后的My Get方法包含以下内容,以便将响应另存为变量并将其全部编辑。
let jsonData = pm.response.json()
jsonData.stuff = "PostmanAutomationContractEdit"
jsonData.otherStuff = 45
jsonData.altId1 = "AutoEdit"
function thing(id, classification, foo, foos, barf, contactNb) {
this.id = id
this.classification = classification
this.foo = foo
this.foos = foos
this.barf = barf
this.contactNb = contactNb
}
let newThingData = new thing(pm.environment.get('newContractNb'), "bil", "y", "n", jsonData.thing[0].things, "000914")
jsonData.stuff[0].nextLevelStuff[0] = newPartyData
pm.environment.set('responseEdit', JSON.stringify(jsonData))
然后,我使用体内的变量运行PUT方法。
{{responseEdit}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.