> 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 # ListFolders # Package: mediaManager # Namespace: FoldersService # Method link: https://dev.wix.com/docs/api-reference/assets/media/media-manager/folders/list-folders.md ## Permission Scopes: Read Media Manager: SCOPE.DC-MEDIA.READ-MEDIAMANAGER ## Introduction 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. --- ## REST API ### Schema ``` Method: listFolders 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 GUID in the `parentFolderId` parameter. If no folder is specified, the method retrieves a list of folders within the root folder of the Media Manager. URL: https://www.wixapis.com/site-media/v1/folders Method: GET Method parameters: param name: paging | type: CursorPaging - name: limit | type: integer | description: Maximum number of items to return in the results. - name: cursor | type: string | description: Pointer to the next or previous page in the list of results. Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request. query param name: parentFolderId | type: parentFolderId | description: GUID of the folder's parent folder. Default: `media-root` folder. param name: sort | type: Sorting - name: fieldName | type: string | description: Name of the field to sort by. - name: order | type: SortOrder | description: Sort order. - enum: ASC, DESC Return type: ListFoldersResponse - name: folders | type: array | description: Information about the folders in the requested folder. - name: id | type: string | description: Folder GUID. Generated when a folder is created in the Media Manager. - name: displayName | type: string | description: Folder name as it appears in the Media Manager. - name: parentFolderId | type: string | description: GUID of the folder's parent folder.
Default: `media-root` folder. - name: createdDate | type: string | description: Date the folder was created. - name: updatedDate | type: string | description: Date the folder was updated. - name: state | type: State | description: State of the folder. - enum: OK, DELETED - name: siteId | type: string | description: Site GUID the folder belongs to. - name: nextCursor | type: PagingMetadataV2 | description: The next cursor if it exists. - name: total | type: integer | description: Total number of items that match the query. Returned if offset paging is used and the `tooManyToCount` flag is not set. - name: cursors | type: Cursors | description: Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used. - name: next | type: string | description: Cursor string pointing to the next page in the list of results. ``` ### Examples ### List folders in a specific parent folder This example sorts by `displayName` in `DESC` order with a paging limit of 2. ```curl curl -X GET \ 'https://www.wixapis.com/site-media/v1/folders?parentFolderId=25284aa06584441ea94338fdcfbaba12&sort.fieldName=displayName&sort.order=DESC&paging.limit=2' \ -H 'Authorization: ' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.mediaManager.FoldersService.listFolders(options) 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 GUID 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 parameters: param name: options | type: ListFoldersOptions none - name: parentFolderId | type: string | description: GUID of the folder's parent folder. Default: `media-root` folder. - name: sort | type: Sorting | description: Field name and order to sort by. One of: `displayName` `updatedDate` Default: `updatedDate` in `desc` order. - name: fieldName | type: string | description: Name of the field to sort by. - name: order | type: SortOrder | description: Sort order. - enum: ASC, DESC - name: paging | type: CursorPaging | description: Cursor and paging information. - name: limit | type: integer | description: Maximum number of items to return in the results. - name: cursor | type: string | description: Pointer to the next or previous page in the list of results. Pass the relevant cursor token from the `pagingMetadata` object in the previous call's response. Not relevant for the first request. Return type: PROMISE - name: folders | type: array | description: Information about the folders in the requested folder. - name: _id | type: string | description: Folder GUID. Generated when a folder is created in the Media Manager. - name: displayName | type: string | description: Folder name as it appears in the Media Manager. - name: parentFolderId | type: string | description: GUID of the folder's parent folder.
Default: `media-root` folder. - name: _createdDate | type: Date | description: Date the folder was created. - name: _updatedDate | type: Date | description: Date the folder was updated. - name: state | type: State | description: State of the folder. - enum: OK, DELETED - name: siteId | type: string | description: Site GUID the folder belongs to. - name: nextCursor | type: PagingMetadataV2 | description: The next cursor if it exists. - name: total | type: integer | description: Total number of items that match the query. Returned if offset paging is used and the `tooManyToCount` flag is not set. - name: cursors | type: Cursors | description: Cursors to navigate through the result pages using `next` and `prev`. Returned if cursor paging is used. - name: next | type: string | description: Cursor string pointing to the next page in the list of results. ``` ### Examples ### Create a folder from visitor input (with $w) This code is an example of a page on which a visitor chooses a folder from a dropdown list, and then creates a folder within that folder. ```javascript /****************************************** * Backend code - create-folder.web.js/ts * *****************************************/ import { Permissions, webMethod } from '@wix/web-methods'; import { folders } from '@wix/media'; import { auth } from '@wix/essentials'; 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 createFolder = webMethod(Permissions.Anyone, async (displayName, options) => { try { const elevateCreateFolder = auth.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 folderList = await listFolders(); const dropdownOptions = folderList.folders.map((folder) => { return { label: folder.displayName, value: folder._id }; }); $w('#foldersDropdown').options = dropdownOptions; }; ``` ### List 5 folders found in a parent folder, sorted alphabetically by name (with elevated permissions) ```javascript import { folders } from '@wix/media'; import { auth } from '@wix/essentials'; const elevatedListFolders = auth.elevate(folders.listFolders); /* Sample options value: * { * paging: { * limit: 5 * }, * parentFolderId : '103601562ec94214bee61f470b403dd5', * sort : { * fieldName : 'displayName', * order : 'ASC' * } * } */ export async function myListFoldersFunction(options) { try { const result = await elevatedListFolders(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 * } * } */ ``` ### List 5 folders found in a parent folder, sorted alphabetically by name ```javascript import { folders } from '@wix/media'; import { auth } from '@wix/essentials'; /* Sample options value: * { * paging: { * limit: 5 * }, * parentFolderId : '103601562ec94214bee61f470b403dd5', * sort : { * fieldName : 'displayName', * order : 'ASC' * } * } */ export async function myListFoldersFunction(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 * } * } */ ``` ### List folders (with elevated permissions) ```javascript import { folders } from '@wix/media'; import { auth } from '@wix/essentials'; const elevatedListFolders = auth.elevate(folders.listFolders); async function myListFoldersFunction() { try { const foldersList = await elevatedListFolders(); 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 ```javascript import { folders } from '@wix/media'; 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 * } * } */ ``` ### listFolders (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 listFolders(options) { const response = await myWixClient.folders.listFolders(options); }; ``` ---