如何在邮递员中自动生成此有效载荷。请参阅下面的结构。
我仅更改有效负载中的帐号/帐户名。如果我为客户ID添加200个帐户,则必须在数组中插入200个单独的结构。是否有更好的方法来动态维护和生成有效负载,因为我知道只有2个字段在变化,因此我可以将它们作为变量传递。 我尝试了Collection Runner,但无法将它们作为一个请求发送。
仅供参考-对于另一家公司,则为100或50或500,我希望对任何请求使用相同的有效载荷。
{
"context": {
"EID": "ACC_123",
"eventTime": "2018-01-02T00:00:00.000Z",
"Eaction": "INIT"
},
"payload": [
{
"accountNumber": "12345",
"accountName": "abcd",
"accountAliasName": "",
"customerId": "150740000",
"ccy": "THB",
"accountStatus": "A",
"branch": "001",
"bankCode":"0001"
},
{
"accountNumber": "123456",
"accountName": "abcde",
"accountAliasName": "",
"customerId": "150740001",
"ccy": "THB",
"accountStatus": "A",
"branch": "001",
"bankCode":"0001"
}
]
已更新-
前提条件:
payloadarr.push(
{
"accountNumber": Account_Number ,
"accountName": Account_Name,
...
"context": {
"eventID": "TEST_JSL_0120191",
"eventTime": "2018-01-02T00:00:00.000Z",
"action": "INITIATE"
},
"payload": [payloadarr]
身体:
{{AccountActivation_Payload}}
...
请求已通过:
{"context":{"eventID":"TEST_JSL_0120191","eventTime":"2018-01-02T00:00:00.000Z","action":"INITIATE"},"payload":[[]]}
期望: 有效负载应具有附加值
{"context":{"eventID":"TEST_JSL_0120191","eventTime":"2018-01-02T00:00:00.000Z","action":"INITIATE"},"payload":[{
"accountNumber": "12345",
"accountName": "abcd",
"accountAliasName": "",
"customerId": "150740000",
"ccy": "THB",
"accountStatus": "A",
"branch": "001",
"bankCode":"0001"
},]}
答案 0 :(得分:0)
您可以创建以下var requestBody = {
"context": {
"EID": "ACC_123",
"eventTime": "2018-01-02T00:00:00.000Z",
"Eaction": "INIT"
},
"payload": []
};
for (var i = 0; i < 200; i++) {
requestBody.payload.push({
"accountNumber": 12345 + i,
"accountName": "abcd" + i,
"accountAliasName": "",
"customerId": "150740000",
"ccy": "THB",
"accountStatus": "A",
"branch": "001",
"bankCode": "0001"
});
}
postman.setEnvironmentVariable('requestBody', JSON.stringify(requestBody));
requestBody
并设置了环境变量{{requestBody}}
,然后您可以使用<table class="table table-bordered">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
</tbody>
在请求正文中调用它