> Portal Navigation:
>
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt
# BulkDeleteFolders
# Package: mediaManager
# Namespace: FoldersService
# Method link: https://dev.wix.com/docs/api-reference/assets/media/media-manager/folders/bulk-delete-folders.md
## Permission Scopes:
Manage Media Manager: SCOPE.DC-MEDIA.MANAGE-MEDIAMANAGER
## Introduction
Temporarily deletes the specified folders from the Media Manager.
The deleted folders are moved to the Media Manager's `trash-root` folder (trash bin) unless permanently deleted. To permanently delete folders, specify the `permanent` parameter with the value `true`. Permanently deleting folders isn't reversible, so make sure that the files in these folders aren't being used in a site or in any other way as the files will no longer be accessible.
Note the following:
* When a folder is deleted, the files in that folder are deleted.
* The specified folders can be from different parent folders.
* Moving multiple folders at once is an asynchronous action, and may take time for the changes to appear in the Media Manager.
* Attempting to delete folders that are already in the trash bin doesn't result in an error.
* If a site contains files from a deleted media folder, the files still appear on the site as the deleted folder is still in the Media Manager (in the trash bin).
* You can also use the [Bulk Restore Folders From Trash Bin](https://dev.wix.com/docs/rest/assets/media/media-manager/folders/bulk-restore-folders-from-trash-bin.md) method to restore folders from the Media Manager's trash bin.
---
## REST API
### Schema
```
Method: bulkDeleteFolders
Description: Temporarily deletes the specified folders from the Media Manager.
The deleted folders are moved to the Media Manager's `trash-root` folder (trash bin) unless permanently deleted. To permanently delete folders, specify the `permanent` parameter with the value `true`. Permanently deleting folders isn't reversible, so make sure that the files in these folders aren't being used in a site or in any other way as the files will no longer be accessible. Note the following: * When a folder is deleted, the files in that folder are deleted. * The specified folders can be from different parent folders. * Moving multiple folders at once is an asynchronous action, and may take time for the changes to appear in the Media Manager. * Attempting to delete folders that are already in the trash bin doesn't result in an error. * If a site contains files from a deleted media folder, the files still appear on the site as the deleted folder is still in the Media Manager (in the trash bin). * You can also use the [Bulk Restore Folders From Trash Bin](https://dev.wix.com/docs/rest/assets/media/media-manager/folders/bulk-restore-folders-from-trash-bin.md) method to restore folders from the Media Manager's trash bin.
URL: https://www.wixapis.com/site-media/v1/bulk/folders/delete
Method: POST
# Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
Required parameters: folderIds
Method parameters:
param name: folderIds | type: array | description: IDs of the folders to move to the Media Manager's trash bin. | required: true
param name: permanent | type: permanent | description: Whether the specified folders are permanently deleted.
Default: `false`
Return type: BulkDeleteFoldersResponse
EMPTY-OBJECT {}
```
### Examples
### Bulk delete folders
```curl
curl -X POST \
'https://www.wixapis.com/site-media/v1/bulk/folders/delete' \
-H 'Authorization: ' \
-H 'Content-Type: application/json' \
--data-binary '{
"folderIds": ["25284aa06584441ea94338fdcfbaba12", "9v38fdcfbaba12eeb55bcf5c41eca01c0"]
}'
```
---
## JavaScript SDK
### Schema
```
Method: wixClientAdmin.mediaManager.FoldersService.bulkDeleteFolders(folderIds, options)
Description: Temporarily deletes the specified folders from the Media Manager.
The deleted folders are moved to the Media Manager's `trash-root` folder (trash bin) unless permanently deleted. To permanently delete folders, specify the `permanent` parameter with the value `true`. Permanently deleting folders isn't reversible, so make sure that the files in these folders aren't being used in a site or in any other way as the files will no longer be accessible. Note the following: * When a folder is deleted, the files in that folder are deleted. * The specified folders can be from different parent folders. * Moving multiple folders at once is an asynchronous action, and may take time for the changes to appear in the Media Manager. * Attempting to delete folders that are already in the trash bin doesn't result in an error. * If a site contains files from a deleted media folder, the files still appear on the site as the deleted folder is still in the Media Manager (in the trash bin). * You can also use the [Bulk Restore Folders From Trash Bin](https://dev.wix.com/docs/rest/assets/media/media-manager/folders/bulk-restore-folders-from-trash-bin.md) method to restore folders from the Media Manager's trash bin.
# Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
Required parameters: folderIds
Method parameters:
param name: folderIds | type: array | description: IDs of the folders to move to the Media Manager's trash bin. | required: true
param name: options | type: BulkDeleteFoldersOptions none
- name: permanent | type: boolean | description: Whether the specified folders are permanently deleted.
Default: `false`
Return type: PROMISE
EMPTY-OBJECT {}
```
### Examples
### Bulk delete folders (with elevated permissions)
```javascript
import { folders } from '@wix/media';
import { auth } from '@wix/essentials';
/* Sample folderIds value:
* [
* '302fc049d70c41dea33fa4a27ab481ba',
* 's8ze556gf8wfao3us62nx25ww3lr595a'
* ]
*/
const elevatedBulkDeleteFolders = auth.elevate(folders.bulkDeleteFolders);
async function myBulkDeleteFoldersFunction(folderIds) {
try {
const deletedFolders = await elevatedBulkDeleteFolders(folderIds);
console.log('Successfully moved folders to trash.');
return deletedFolders;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to void */
```
### Bulk delete folders
```javascript
import { folders } from '@wix/media';
/* Sample folderIds value:
* [
* '302fc049d70c41dea33fa4a27ab481ba',
* 's8ze556gf8wfao3us62nx25ww3lr595a'
* ]
*/
async function myBulkDeleteFoldersFunction(folderIds) {
try {
const deletedFolders = await folders.bulkDeleteFolders(folderIds);
console.log('Successfully moved folders to trash.');
return deletedFolders;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to void */
```
### Bulk delete all folders (with $w)
This code is an example of a page on which a visitor chooses a folder from a dropdown list, and then deletes all folders found within that folder.
```javascript
/*******************************************
* Backend code - delete-folders.web.js/ts *
******************************************/
import { Permissions, webMethod } from '@wix/web-methods';
import { folders } from '@wix/media';
import { auth } from '@wix/essentials';
export const deleteFolders = webMethod(Permissions.Anyone, async (folderIds) => {
try {
const elevatedBulkDeleteFolders = auth.elevate(folders.bulkDeleteFolders);
const deletedFolders = await elevatedBulkDeleteFolders(folderIds);
console.log('Successfully moved folders to trash.');
return deletedFolders;
} catch (error) {
console.error(error);
}
});
export const listFolders = webMethod(Permissions.Anyone, async () => {
try {
const elevatedListFolders = auth.elevate(folders.listFolders)
const foldersList = await elevatedListFolders();
return foldersList;
} catch (error) {
console.error(error);
}
});
export const searchFolders = webMethod(Permissions.Anyone, async (options) => {
try {
const elevatedSearchFolders = auth.elevate(folders.searchFolders)
const foldersFound = await elevatedSearchFolders(options);
return foldersFound;
} catch (error) {
console.error(error);
}
});
/*************
* Page code *
************/
import { deleteFolders, listFolders, searchFolders } from 'backend/delete-folders.web';
$w.onReady(async () => {
await populateFoldersDropdown();
$w('#bulkDelete').onClick(async () => {
const searchOptions = { rootFolder: $w('#foldersDropdown').value};
const foldersToDelete = await searchFolders(searchOptions);
const foldersIdsToDelete = foldersToDelete.folders.map((folder) => {
return folder._id;
});
await deleteFolders(foldersIdsToDelete);
console.log(`Successfully deleted all folders found in ${$w('#foldersDropdown').label}.`)
$w('#bulkDeleteSuccessMsg').show();
});
});
async function populateFoldersDropdown() {
const folderList = await listFolders();
const dropdownOptions = folderList.folders.map((folder) => {
return {
label: folder.displayName,
value: folder._id
};
});
$w('#foldersDropdown').options = dropdownOptions;
};
```
### Bulk permanently delete folders (with elevated permissions)
```javascript
import { folders } from '@wix/media';
import { auth } from '@wix/essentials';
/* Sample folderIds value:
* [
* '302fc049d70c41dea33fa4a27ab481ba',
* 's8ze556gf8wfao3us62nx25ww3lr595a',
* 'c956d69906414e7faf8a0ad81117b17d'
* ]
*
* Sample options value:
* {
* permanent: true
* }
*/
export async function myBulkDeleteFoldersFunction(folderIds, options) {
try {
const elevatedBulkDeleteFolders = auth.elevate(folders.bulkDeleteFolders);
const deletedFolders = await elevatedBulkDeleteFolders(folderIds, options);
console.log('Successfully permanently deleted files.');
return deletedFolders;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to void */
```
### Bulk permanently delete folders
```javascript
import { folders } from '@wix/media';
/* Sample folderIds value:
* [
* '302fc049d70c41dea33fa4a27ab481ba',
* 's8ze556gf8wfao3us62nx25ww3lr595a',
* 'c956d69906414e7faf8a0ad81117b17d'
* ]
*
* Sample options value:
* {
* permanent: true
* }
*/
export async function myBulkDeleteFoldersFunction(folderIds, options) {
try {
const deletedFolders = await folders.bulkDeleteFolders(folderIds, options);
console.log('Successfully permanently deleted files.');
return deletedFolders;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to void */
```
### bulkDeleteFolders (self-hosted)
Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).
```javascript
import { createClient } from '@wix/sdk';
import { folders } from '@wix/media';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed
const myWixClient = createClient ({
modules: { folders },
// Include the auth strategy and host as relevant
});
async function bulkDeleteFolders(folderIds,options) {
const response = await myWixClient.folders.bulkDeleteFolders(folderIds,options);
};
```
---