如何在逻辑应用中批量向api发送请求
How to send requests to api in batches in logic app
我有一个逻辑应用程序,我在其中使用 javascript 内联代码创建 json 请求并将其发送到 api。 json 请求中可能有超过 1000 个请求。我需要将这些请求以 200 个为一批发送到 api。如何在逻辑应用中实现批处理?
这个需求可以参考下面的js代码:
//First define a function to do the separate arry operation
function group(array, subGroupLength) {
let index = 0;
let newArray = [];
while(index < array.length) {
newArray.push(array.slice(index, index += subGroupLength));
}
return newArray;
}
//Then use the "group(array, subGroupLength)" function to separate your array to multiple 200 records array
var resultArray = group(json.records, 200);
return resultArray;
根据代码,resultArray 应该是这样的:
[
[
{
"attributes": {
"Id": ""
},
"Property": ID1,
"Type": ""
},
.....
//200 items
.....
{
"attributes": {
"Id": ""
},
"Property": ID1,
"Type": ""
}
],
....
//five sub array
....
[
{
"attributes": {
"Id": ""
},
"Property": ID1,
"Type": ""
},
.....
//200 items
.....
{
"attributes": {
"Id": ""
},
"Property": ID1,
"Type": ""
}
]
]
===============================更新=== ========================
针对您关于 give all those sub arrays a name(same name for all sub arrays)
的新要求,我修改了 function group(array, subGroupLength)
的代码,如下所示:
function group(array, subGroupLength) {
let index = 0;
let newArray = [];
while(index < array.length) {
let item = array.slice(index, index += subGroupLength);
let itemObj = {"subArray": item};
//newArray.push(array.slice(index, index += subGroupLength));
newArray.push(itemObj);
}
return newArray;
}
在我的代码中,每个子数组的名称是 subArray
。请检查是否符合您的要求。
我有一个逻辑应用程序,我在其中使用 javascript 内联代码创建 json 请求并将其发送到 api。 json 请求中可能有超过 1000 个请求。我需要将这些请求以 200 个为一批发送到 api。如何在逻辑应用中实现批处理?
这个需求可以参考下面的js代码:
//First define a function to do the separate arry operation
function group(array, subGroupLength) {
let index = 0;
let newArray = [];
while(index < array.length) {
newArray.push(array.slice(index, index += subGroupLength));
}
return newArray;
}
//Then use the "group(array, subGroupLength)" function to separate your array to multiple 200 records array
var resultArray = group(json.records, 200);
return resultArray;
根据代码,resultArray 应该是这样的:
[
[
{
"attributes": {
"Id": ""
},
"Property": ID1,
"Type": ""
},
.....
//200 items
.....
{
"attributes": {
"Id": ""
},
"Property": ID1,
"Type": ""
}
],
....
//five sub array
....
[
{
"attributes": {
"Id": ""
},
"Property": ID1,
"Type": ""
},
.....
//200 items
.....
{
"attributes": {
"Id": ""
},
"Property": ID1,
"Type": ""
}
]
]
===============================更新=== ========================
针对您关于 give all those sub arrays a name(same name for all sub arrays)
的新要求,我修改了 function group(array, subGroupLength)
的代码,如下所示:
function group(array, subGroupLength) {
let index = 0;
let newArray = [];
while(index < array.length) {
let item = array.slice(index, index += subGroupLength);
let itemObj = {"subArray": item};
//newArray.push(array.slice(index, index += subGroupLength));
newArray.push(itemObj);
}
return newArray;
}
在我的代码中,每个子数组的名称是 subArray
。请检查是否符合您的要求。