0

When I finish one request I'm creating an array in the collectionVariables to store an Id that come from response. Then I need use this array to send request to delete all my content

(storing the 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);

To delete this contents I need to loop with forEach function. For it I need set the arrays info in the {{ID}} endpoint

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)

My question is, how can I loop this pre-request to delete my content ?

  • Welcome to Stackoverflow, remember that this is not a general help forum, so can you explain what the actual programming problem is that you're running into? Because it sounds like you're not quite at the point where posting to SO makes sense: if you need to loop over your array, then the immediate response is "okay, sounds good, write out that code and see if it does what you need?". You have your `idArray`, so start iterating through it, probably using a `for...of` with `await` (see https://stackoverflow.com/questions/37576685) – Mike 'Pomax' Kamermans Oct 18 '21 at 16:53

0 Answers0