> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: listFolders(options: ListFoldersOptions)

# Method package: wixMediaV2

# Method menu location: wixMediaV2 --> folders --> listFolders

# Method Link: https://dev.wix.com/docs/velo/apis/wix-media-v2/folders/list-folders.md

# Method Description:

Retrieves a list of folders in the Media Manager. To retrieve a list of folders within a specific folder in the Media Manager, specify the specific folder's ID in the `parentFolderId` parameter. If no folder is specified, the method retrieves a list of folders within the root folder of the Media Manager.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## List folders (dashboard page code)

```javascript
import { folders } from 'wix-media.v2';

async function myListFoldersFunction()
{
  try {
    const foldersList = await folders.listFolders();

    console.log("Folders:", foldersList);
    return foldersList;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "folders": [
 *     {
 *       "_createdDate": "2023-08-14T07:41:19.000Z",
 *       "_id": "103601562ec94214bee61f470b403dd5",
 *       "_updatedDate": "2023-08-14T07:41:19.000Z",
 *       "displayName": "Pictures",
 *       "parentFolderId": "media-root",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-14T07:38:31.000Z",
 *       "_id": "c956d69906414e7faf8a0ad81117b17d",
 *       "_updatedDate": "2023-08-14T07:38:31.000Z",
 *       "displayName": "Videos",
 *       "parentFolderId": "media-root",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-09T08:57:12.000Z",
 *       "_id": "b2bc72834460412494c93617d88b8c89",
 *       "_updatedDate": "2023-08-09T08:57:12.000Z",
 *       "displayName": "Documents",
 *       "parentFolderId": "media-root",
 *       "state": "OK"
 *     }
 *   ],
 *   "nextCursor": {
 *     "cursors": {
 *       "next": ""
 *     },
 *     "hasNext": false
 *   }
 * }
 */
```

## List folders (export from backend code)

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { folders } from 'wix-media.v2';
import { elevate } from 'wix-auth';

export const myListFoldersFunction = webMethod(Permissions.Anyone, async () => {
  try {
    const elevatedListFolders = elevate(folders.listFolders);
    const folderList = await elevatedListFolders();

    console.log("Folders:", folderList);
    return folderList;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
});

/* Promise resolves to:
 * {
 *   "folders": [
 *     {
 *       "_createdDate": "2023-08-14T07:41:19.000Z",
 *       "_id": "103601562ec94214bee61f470b403dd5",
 *       "_updatedDate": "2023-08-14T07:41:19.000Z",
 *       "displayName": "Pictures",
 *       "parentFolderId": "media-root",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-14T07:38:31.000Z",
 *       "_id": "c956d69906414e7faf8a0ad81117b17d",
 *       "_updatedDate": "2023-08-14T07:38:31.000Z",
 *       "displayName": "Videos",
 *       "parentFolderId": "media-root",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-09T08:57:12.000Z",
 *       "_id": "b2bc72834460412494c93617d88b8c89",
 *       "_updatedDate": "2023-08-09T08:57:12.000Z",
 *       "displayName": "Documents",
 *       "parentFolderId": "media-root",
 *       "state": "OK"
 *     }
 *   ],
 *   "nextCursor": {
 *     "cursors": {
 *       "next": ""
 *     },
 *     "hasNext": false
 *   }
 * }
 */
```

## List 5 folders found in a parent folder, sorted alphabetically by name 

```javascript
import { folders } from 'wix-media.v2';
import { elevate } from 'wix-auth';
import { Permissions, webMethod } from 'wix-web-module';

/* Sample options value:
 * {
 *   paging: {
 *       limit: 5
 *   },
 *   parentFolderId : '103601562ec94214bee61f470b403dd5',
 *   sort : {
 *       fieldName : 'displayName',
 *       order : 'ASC'
 *   }
 * }
 */

export const myListFoldersFunction = webMethod(Permissions.Anyone, async (options) => {
  try {
    const result = await folders.listFolders(options);

    const folderList = result.folders;

    folderList.forEach(element => {
      console.log(element.displayName);
    });

    return result;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
});

/* Promise resolves to:
 * {
 *   "folders": [
 *     {
 *       "_createdDate": "2023-08-21T09:33:47.000Z",
 *       "_id": "0cfdf68ac3b9453b81cfe171caf40b0c",
 *       "_updatedDate": "2023-08-21T09:33:47.000Z",
 *       "displayName": "31-08",
 *       "parentFolderId": "103601562ec94214bee61f470b403dd5",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-21T09:33:30.000Z",
 *       "_id": "193161aeef8f4b80b97d7032fb2c4f0a",
 *       "_updatedDate": "2023-08-21T11:09:58.000Z",
 *       "displayName": "Water",
 *       "parentFolderId": "103601562ec94214bee61f470b403dd5",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-21T09:32:39.000Z",
 *       "_id": "4b9e2dd061de4f3e80e3ada23b0fb440",
 *       "_updatedDate": "2023-08-21T09:32:39.000Z",
 *       "displayName": "city",
 *       "parentFolderId": "103601562ec94214bee61f470b403dd5",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-21T09:56:43.000Z",
 *       "_id": "6a86df2ce32c4d279c21fbdd2887c18b",
 *       "_updatedDate": "2023-08-21T09:56:43.000Z",
 *       "displayName": "docs1",
 *       "parentFolderId": "103601562ec94214bee61f470b403dd5",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-21T09:33:10.000Z",
 *       "_id": "5d0625ed28494bf7938c03e9a21130ba",
 *       "_updatedDate": "2023-08-21T09:33:24.000Z",
 *       "displayName": "docs2",
 *       "parentFolderId": "103601562ec94214bee61f470b403dd5",
 *       "state": "OK"
 *     },
 *     {
 *       "_createdDate": "2023-08-21T09:32:34.000Z",
 *       "_id": "7984b3c5454e4371acbd4f4eedde96bc",
 *       "_updatedDate": "2023-08-21T11:10:51.000Z",
 *       "displayName": "mountains",
 *       "parentFolderId": "103601562ec94214bee61f470b403dd5",
 *       "state": "OK"
 *     }
 *   ],
 *   "nextCursor": {
 *     "cursors": {
 *       "next": ""
 *     },
 *     "hasNext": false
 *   }
 * }
 */
```

## Create a folder from visitor input 

```javascript
/***************************************
 * Backend code - create-folder.web.js *
 **************************************/

import { Permissions, webMethod } from 'wix-web-module';
import { folders } from 'wix-media.v2';
import { elevate } from 'wix-auth';

export const listFolders = webMethod(Permissions.Anyone, async () => {
  try {
    const elevatedListFolders = elevate(folders.listFolders)
    const foldersList = await elevatedListFolders();

    return foldersList;
  } catch (error) {
    console.error(error);
  }
});

export const createFolder = webMethod(Permissions.Anyone, async (displayName, options) => {
  try {
    const elevateCreateFolder = elevate(folders.createFolder);
    const newFolder = await elevateCreateFolder(displayName, options);

    return newFolder;
  } catch (err){
    console.error(err);
  }
});

/*************
 * Page code *
 ************/

import { createFolder, listFolders } from 'backend/create-folder.web';

$w.onReady(async () => {
  await populateFoldersDropdown();

  $w('#createFolder').onClick(async () => {
    const folderName = $w('folderName').value;
    const createOptions = {parentFolderId: $w('foldersDropdown').value};
    const newFolder = await createFolder(folderName, createOptions);

    console.log(`Successfully created new folder "${folderName}" in ${$w('#foldersDropdown').label}.`)
    $w('#createdFolderSuccessMsg').show();
  });
});

async function populateFoldersDropdown() {
  const folders = await listFolders();
  const dropdownOptions = folders.map((folder) => {
    return {
      label: folder.displayName,
      value: folder._id
    };
  });

  $w('#foldersDropdown').options = dropdownOptions;
};
```

---