# Postman delete multiple resource IDs

**URL:** <https://community.postman.com/t/postman-delete-multiple-resource-ids/42142>\
**Category:** Help Hub\
**Created:** [December 16, 2022, 1:09pm UTC](https://community.postman.com/t/postman-delete-multiple-resource-ids/42142 "2022-12-16T13:09:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vio](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@Vio](https://community.postman.com/u/Vio)\
**Post date:** [December 16, 2022, 1:09pm UTC](https://community.postman.com/t/postman-delete-multiple-resource-ids/42142/1 "2022-12-16T13:09:57Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) before creating a new topic.**

> Here’s an outline with best practices for making your inquiry.

_My question_: POSTMAN: How to delete multiple Resource IDs in one go?

_Details (like screenshots)_:  
I have a list of 30 resources IDs and would like to use {{url}}/resource\_delete on Postman adding this list of IDs

_How I found the problem_:  
N/A

_I’ve already tried_:  
{  
“id”: “{{id}}”  
}

let resources = pm.collectionVariables.get(“resources”);

if(!resources || resources.length == 0)

{

resources = [“ba08971c-83de-777c-beb2-2dbe91e727e6”,

“c6ec9412-e19e-999-bcc8-0a9900f3c0ba”,

“268e8bd9-3381-0000-81d3-38fd4fa11110”

];

}

let currentResources = resources.shift();

pm.collectionVariables.set(“id”, currentResources);

pm.collectionVariables.set(“resources”, resources);

const resources = pm.collectionVariables.get(“resources”);

if (resources && resources.length \> 0){  
postman.setNextRequest(“multiple\_resources\_delete\_inonego”);  
} else {  
postman.setNextRequest(null);  
}

pm.test(“Status code is 200”, function () {  
pm.response.to.have.status(200);  
});

But it doesnt loop. I have to run (pushing the button SEND) 3 times to delete these 3 resources

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [December 19, 2022, 1:35pm UTC](https://community.postman.com/t/postman-delete-multiple-resource-ids/42142/2 "2022-12-19T13:35:17Z")

</div>

The following should work. (This is running against postman echo and I’ve just put the {{id}} into the URL instead of the body.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/b/0be7efeb1caf6d1d434362df0aaa39ef5c9ffb50.png)

Pre-request script.

```auto
var array = JSON.parse(pm.collectionVariables.get("resources"));

if(array.length === 0){
    array = [
        "ba08971c-83de-777c-beb2-2dbe91e727e6",
        "c6ec9412-e19e-999-bcc8-0a9900f3c0ba",
        "268e8bd9-3381-0000-81d3-38fd4fa11110"
    ];
}

pm.test("pre-req array is not empty", () => {
    pm.expect(array).to.be.an("array").that.is.not.empty; 
});

var currentResource = array.shift();

pm.collectionVariables.set("id",currentResource);
pm.collectionVariables.set("resources", JSON.stringify(array));

```

Tests tab.

```auto
var array = JSON.parse(pm.collectionVariables.get("resources"));

var expectedResponse = pm.collectionVariables.get("id");
var actualResponse = pm.response.json().args.test;

pm.test(`tests-tab id = ${expectedResponse}`, () => {
    pm.expect(actualResponse).to.eql(expectedResponse); 
});

if (array.length > 0){
postman.setNextRequest("multiple_resources_delete_inonego");

} else {
postman.setNextRequest(null);
}

```

Run history. One iteration (run three times).

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/1/9/1958f36f0497807720c5551fab799b05853444a8.png)

I think the bit you are missing is the storing of the array. Variables are stored as strings, so you have to Stringify them when storing, and JSON.parse when retrieving otherwise they will just be viewed as a string (not an array).

However I swear that the example I had previously saved and tested for this exact scenario didn’t need to do this.

It took me a while to work out what was going wrong, and amending the storing and retrieving of the array fixed it.

You need to have something in the resources array, or the first line of the pre-request script will error (as it needs something, even if its a blank “” array. It can’t just be empty though.

Pretty sure I didn’t need to do this previously either.

Not sure if something changed with how variables are stored in Postman 10, as it took me while to get this working again but it does work.

---

<div class="post-metadata">

**Author:** ![Vio](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@Vio](https://community.postman.com/u/Vio)\
**Post date:** [December 19, 2022, 3:09pm UTC](https://community.postman.com/t/postman-delete-multiple-resource-ids/42142/3 "2022-12-19T15:09:53Z")

</div>

thank you very much for your help.  
why do you think I’ve got this error?  
There was an error in evaluating the Pre-request Script:JSONError: No data, empty input at 1:1 ^

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [December 19, 2022, 3:30pm UTC](https://community.postman.com/t/postman-delete-multiple-resource-ids/42142/4 "2022-12-19T15:30:02Z")

</div>

There has to be something in the variable.

Even if its just the square brackets (blank array). Otherwise the JSON.parse will error.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/a/ba8150459e43eb3ce4cb7ada8f1ec4f8e73c8188.png)
