> 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 # QueryFolders # Package: mediaManager # Namespace: FoldersService # Method link: https://dev.wix.com/docs/api-reference/assets/media/media-manager/folders/query-folders.md ## Permission Scopes: Read Media Manager: SCOPE.DC-MEDIA.READ-MEDIAMANAGER ## Introduction Retrieves a list of folders in the Media Manager, given the provided [cursor paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md#cursor-paging), filtering, and sorting. Up to 200 folders can be returned per request. To learn about working with *Query* methods, see [API Query Language](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md) and [Sorting and Paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-sorting-and-paging.md) --- ## REST API ### Schema ``` Method: queryFolders Description: Retrieves a list of folders in the Media Manager, given the provided [cursor paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md#cursor-paging), filtering, and sorting. Up to 200 folders can be returned per request. To learn about working with *Query* methods, see [API Query Language](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md) and [Sorting and Paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-sorting-and-paging.md) URL: https://www.wixapis.com/site-media/v1/folders/query Method: POST Method parameters: param name: query | type: CursorQuery - name: cursorPaging | type: CursorPaging | description: Cursor paging options. Learn more about [cursor paging](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#cursor-paging). - 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. - name: filter | type: object | description: Filter object. Learn more about [filtering](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#filters). - name: sort | type: array | description: Sort object. Learn more about [sorting](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#sorting). - name: fieldName | type: string | description: Name of the field to sort by. - name: order | type: SortOrder | description: Sort order. Use `ASC` for ascending order or `DESC` for descending order. Default: `ASC` - enum: ASC, DESC Return type: QueryFoldersResponse - name: folders | type: array | description: Retrieved folders that match the query. - 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: pagingMetadata | type: PagingMetadataV2 | description: Paging metadata, including the cursors for the next and previous pages. - 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 ### Search folders ```curl curl -X POST \ 'https://www.wixapis.com/site-media/v1/folders/query' \ -H 'Authorization: ' --data-binary '{ "query": { "filter": { "state": "OK" }, "sort": { "fieldName": "updatedDate", "order": "DESC" }, "cursorPaging": { "cursor": "test_cursor", "limit": 10 } } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.mediaManager.FoldersService.queryFolders(query) Description: Retrieves a list of folders in the Media Manager, given the provided [cursor paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md#cursor-paging), filtering, and sorting. Up to 200 folders can be returned per request. To learn about working with *Query* methods, see [API Query Language](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md) and [Sorting and Paging](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-sorting-and-paging.md) # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: query Method parameters: param name: query | type: FolderQuery | required: true - name: cursorPaging | type: CursorPaging | description: Cursor paging options. Learn more about [cursor paging](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#cursor-paging). - 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. - name: filter | type: object | description: Filter object. Learn more about [filtering](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#filters). - name: sort | type: array | description: Sort object. Learn more about [sorting](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md#sorting). - name: fieldName | type: string | description: Name of the field to sort by. - name: order | type: SortOrder | description: Sort order. Use `ASC` for ascending order or `DESC` for descending order. Default: `ASC` - enum: ASC, DESC Return type: PROMISE - name: folders | type: array | description: Retrieved folders that match the query. - 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: pagingMetadata | type: PagingMetadataV2 | description: Paging metadata, including the cursors for the next and previous pages. - 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 ### Query folders with cursor paging Paginate through query results using cursor-based paging. ```javascript import { folders } from '@wix/media'; async function myQueryAllFoldersFunction() { const allFolders = []; let cursor = undefined; let hasNext = true; try { while (hasNext) { const result = await folders.queryFolders({ query: { filter: { state: 'OK', }, cursorPaging: { limit: 50, cursor, }, }, }); allFolders.push(...result.folders); cursor = result.pagingMetadata?.cursors?.next; hasNext = result.pagingMetadata?.hasNext ?? false; } console.log(`Total folders retrieved: ${allFolders.length}`); return allFolders; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * [ * { * "_createdDate": "2023-08-14T07:41:19.000Z", * "_id": "103601562ec94214bee61f470b403dd5", * "_updatedDate": "2023-08-21T11:09:08.000Z", * "displayName": "Pictures", * "parentFolderId": "media-root", * "state": "OK" * }, * { * "_createdDate": "2023-08-21T05:34:03.000Z", * "_id": "302fc049d70c41dea33fa4a27ab481ba", * "_updatedDate": "2023-08-21T05:34:03.000Z", * "displayName": "Videos", * "parentFolderId": "media-root", * "state": "OK" * } * ] */ ``` ### Query folders with filter and sort Filter folders by state and sort by updated date in descending order. ```javascript import { folders } from '@wix/media'; async function myQueryFoldersFunction() { try { const result = await folders.queryFolders({ query: { filter: { state: 'OK', }, sort: { fieldName: 'updatedDate', order: 'DESC', }, cursorPaging: { limit: 10, }, }, }); console.log('Queried folders sorted by updatedDate:', result); return result; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "folders": [ * { * "_createdDate": "2023-08-14T07:41:19.000Z", * "_id": "103601562ec94214bee61f470b403dd5", * "_updatedDate": "2023-08-21T11:09:08.000Z", * "displayName": "Pictures", * "parentFolderId": "media-root", * "state": "OK" * }, * { * "_createdDate": "2023-08-21T05:34:03.000Z", * "_id": "302fc049d70c41dea33fa4a27ab481ba", * "_updatedDate": "2023-08-21T05:34:03.000Z", * "displayName": "Videos", * "parentFolderId": "media-root", * "state": "OK" * } * ], * "pagingMetadata": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ### Query folders with filter Filter folders by state using the query filter syntax. ```javascript import { folders } from '@wix/media'; async function myQueryFoldersFunction() { try { const result = await folders.queryFolders({ query: { filter: { state: 'OK', }, }, }); console.log('Queried folders:', result); return result; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "folders": [ * { * "_createdDate": "2023-08-14T07:41:19.000Z", * "_id": "103601562ec94214bee61f470b403dd5", * "_updatedDate": "2023-08-21T11:09:08.000Z", * "displayName": "Pictures", * "parentFolderId": "media-root", * "state": "OK" * }, * { * "_createdDate": "2023-08-21T05:34:03.000Z", * "_id": "302fc049d70c41dea33fa4a27ab481ba", * "_updatedDate": "2023-08-21T05:34:03.000Z", * "displayName": "Videos", * "parentFolderId": "media-root", * "state": "OK" * } * ], * "pagingMetadata": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ### Query folders (with elevated permissions) ```javascript import { folders } from '@wix/media'; import { auth } from '@wix/essentials'; const elevatedQueryFolders = auth.elevate(folders.queryFolders); async function myQueryFoldersFunction() { try { const result = await elevatedQueryFolders(); console.log('Queried folders:', result); return result; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "folders": [ * { * "_createdDate": "2023-08-14T07:41:19.000Z", * "_id": "103601562ec94214bee61f470b403dd5", * "_updatedDate": "2023-08-21T11:09:08.000Z", * "displayName": "Pictures", * "parentFolderId": "media-root", * "state": "OK" * }, * { * "_createdDate": "2023-08-21T05:34:03.000Z", * "_id": "302fc049d70c41dea33fa4a27ab481ba", * "_updatedDate": "2023-08-21T05:34:03.000Z", * "displayName": "Videos", * "parentFolderId": "media-root", * "state": "OK" * } * ], * "pagingMetadata": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ### Query folders ```javascript import { folders } from '@wix/media'; async function myQueryFoldersFunction() { try { const result = await folders.queryFolders(); console.log('Queried folders:', result); return result; } catch (error) { console.error(error); // Handle the error } } /* Promise resolves to: * { * "folders": [ * { * "_createdDate": "2023-08-14T07:41:19.000Z", * "_id": "103601562ec94214bee61f470b403dd5", * "_updatedDate": "2023-08-21T11:09:08.000Z", * "displayName": "Pictures", * "parentFolderId": "media-root", * "state": "OK" * }, * { * "_createdDate": "2023-08-21T05:34:03.000Z", * "_id": "302fc049d70c41dea33fa4a27ab481ba", * "_updatedDate": "2023-08-21T05:34:03.000Z", * "displayName": "Videos", * "parentFolderId": "media-root", * "state": "OK" * } * ], * "pagingMetadata": { * "cursors": { * "next": "" * }, * "hasNext": false * } * } */ ``` ### queryFolders (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 queryFolders(query) { const response = await myWixClient.folders.queryFolders(query); }; ``` ---