首页 > 解决方案 > 我需要使用数组列表发送请求循环

问题描述

当我完成一个请求时,我将在 collectionVariables 中创建一个数组来存储来自响应的 Id。然后我需要使用这个数组来发送删除我所有内容的请求

(存储ID)

const idArray = pm.collectionVariables.get("idArray2");
response = JSON.parse(responseBody);
// const array = [];
const id = response.items[0].sys.id;
// array.push(id);
// entryId = pm.response.json().items[0].sys.id;
idArray.push(id);
// arrayValue = pm.collectionVariables.get("idArray");
console.log(idArray);
// pm.collectionVariables.set("arrayValue", array);
// arrayValue.push(id);

要删除这些内容,我需要使用 forEach 函数循环。为此,我需要在 {{ID}} 端点中设置数组信息

var submitUnpublishedRequest = {
        url: pm.variables.replaceIn('https://api.contentful.com/spaces/{{spaceId}}/environments/{{branch}}/entries/{{ID}}/published'),
        method: 'DELETE',
        header: {
            'Authorization': "Bearer " + pm.environment.get("contentManagementToken"),
            'aeg-event-type': pm.environment.get("event_type"),
            'aeg-sas-key': pm.environment.get("sas_key"),
            'Content-Type': "application/json"
        },
        body: {}
    } 
 pm.sendRequest(submitUnpublishedRequest)

我的问题是,如何循环此预请求以删除我的内容?

标签: javascriptarraysloopsforeach

解决方案


推荐阅读