> 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

# UpdateFolder

# Package: mediaManager

# Namespace: FoldersService

# Method link: https://dev.wix.com/docs/api-reference/assets/media/media-manager/folders/update-folder.md

## Permission Scopes:
Manage Media Manager: SCOPE.DC-MEDIA.MANAGE-MEDIAMANAGER

## Introduction

Updates a folder. <br />

You can use the `parentFolderId` parameter to move a folder from its current parent folder to a different parent folder.

---

## REST API

### Schema

```
 Method: updateFolder
 Description: Updates a folder. <br />  You can use the `parentFolderId` parameter to move a folder from its current parent folder to a different parent folder.
 URL: https://www.wixapis.com/site-media/v1/folders/{folder.id}
 Method: PATCH
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  folder.id, folder
 Method parameters: 
   param name: folder | type: Folder   | required: true 
        - name: id | type: string | description: Folder GUID. Generated when a folder is created in the Media Manager. | required: true | validation: maxLength 100
        - name: displayName | type: string | description: Folder name as it appears in the Media Manager.  | validation: maxLength 1000
        - name: parentFolderId | type: string | description: GUID of the folder's parent folder. <br /> Default: `media-root` folder.  | validation: maxLength 100
 Return type: UpdateFolderResponse
  - name: folder | type: Folder | description: Information about the updated folder.  
     - name: id | type: string | description: Folder GUID. Generated when a folder is created in the Media Manager.  | validation: maxLength 100
     - name: displayName | type: string | description: Folder name as it appears in the Media Manager.  | validation: maxLength 1000
     - name: parentFolderId | type: string | description: GUID of the folder's parent folder. <br /> Default: `media-root` folder.  | validation: maxLength 100
     - name: createdDate | type: string | description: Date the folder was created.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date the folder was updated.  | read-only: true | validation: format date-time
     - name: state | type: State | description: State of the folder.  | read-only: true 
         - enum:
         -     OK: Folder is ready for use.
         -     DELETED: Folder is deleted.
     - name: siteId | type: string | description: Site GUID the folder belongs to.  | read-only: true | validation: maxLength 100

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: FIELD_MASK_IS_EMPTY_OR_MISSING | Description: `fieldMask` is empty or missing from the request.


```

### Examples

### Update a folder
```curl
curl -X PATCH \
  'https://www.wixapis.com/site-media/v1/folders/12vn4498977596aeebcf5c41eca01c0d99667ac9' \
  -H 'Authorization: <AUTH>' \
  -H 'Content-Type: application/json' \
  -d '{
    "folder": {
      "displayName": "New Folder Name",
      "parentFolderId": "media-root"
    }
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.media.folders.updateFolder(_id, folder)
 Description: Updates a folder. <br />  You can use the `parentFolderId` parameter to move a folder from its current parent folder to a different parent folder.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  _id, folder
 Method parameters: 
   param name: _id | type: string | description: Folder GUID. Generated when a folder is created in the Media Manager. | required: true | validation: maxLength 100
   param name: folder | type: UpdateFolder   | required: true 
        - name: _id | type: string | description: Folder GUID. Generated when a folder is created in the Media Manager.  | validation: maxLength 100
        - name: displayName | type: string | description: Folder name as it appears in the Media Manager.  | validation: maxLength 1000
        - name: parentFolderId | type: string | description: GUID of the folder's parent folder. <br /> Default: `media-root` folder.  | validation: maxLength 100
 Return type: PROMISE<Folder>
  - name: _id | type: string | description: Folder GUID. Generated when a folder is created in the Media Manager.  | validation: maxLength 100
  - name: displayName | type: string | description: Folder name as it appears in the Media Manager.  | validation: maxLength 1000
  - name: parentFolderId | type: string | description: GUID of the folder's parent folder. <br /> Default: `media-root` folder.  | validation: maxLength 100
  - name: _createdDate | type: Date | description: Date the folder was created.  | read-only: true 
  - name: _updatedDate | type: Date | description: Date the folder was updated.  | read-only: true 
  - name: state | type: State | description: State of the folder.  | read-only: true 
     - enum:
     -     OK: Folder is ready for use.
     -     DELETED: Folder is deleted.
  - name: siteId | type: string | description: Site GUID the folder belongs to.  | read-only: true | validation: maxLength 100

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: FIELD_MASK_IS_EMPTY_OR_MISSING | Description: `fieldMask` is empty or missing from the request.


```

### Examples

### Update a folder's location (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 updateFolder = webMethod(Permissions.Anyone, async (id, options) => {
  try {
    const elevatedUpdateFolder = auth.elevate(folders.updateFolder);
    const updatedFolder = await elevatedUpdateFolder(id, options);

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

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

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

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

  $w('#updateFolderLocation').onClick(async () => {
    const folderId = $w('#updateFolderDropdown').value;
    const parentFolderId = $w('#parentFolderDropdown').value;
    if (folderId === parentFolderId) {
        $w('#folderIsParentFolderMsg').show();
        return;
    };
    const options = {parentFolderId};
    const updatedFolder = await updateFolder(folderId, options);

    console.log(`Successfully updated folder ${updatedFolder.displayName}:`, updatedFolder);
    $w('#updateFolderSuccessMsg').show();
  });
});

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

  $w('#updateFolderDropdown').options = dropdownOptions;
  $w('#parentFolderDropdown').options = dropdownOptions;
};

```

### Update a folder's name (with elevated permissions)
```javascript
import { folders } from '@wix/media';
import { auth } from '@wix/essentials';

const elevatedUpdateFolder = auth.elevate(folders.updateFolder);

/* Sample id value: '7984b3c5454e4371aqbd4f4eedde96bc'
 *
 * Sample folder value:
 * {
 *   displayName: 'mountains'
 * }
 */

async function myUpdateFolderFunction(id, options) {
  try {
    const updatedFolder = await elevatedUpdateFolder(id, options);

    console.log(`Updated folder ${updatedFolder.displayName}:`, updatedFolder);
    return updatedFolder;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "_createdDate": "2023-08-21T09:32:34.000Z",
 *   "_id": "7984b3c5454e4371acbd4f4eedde96bc",
 *   "_updatedDate": "2023-08-21T11:10:51.000Z",
 *   "displayName": "mountains",
 *   "parentFolderId": "103601562ec94214bee61f470b403dd5",
 *   "state": "OK"
 * }
 */
```

### Update a folder's name
```javascript
import { folders } from '@wix/media';

/* Sample id value: '7984b3c5454e4371aqbd4f4eedde96bc'
 *
 * Sample folder value:
 * {
 *   displayName: 'mountains'
 * }
 */

async function myUpdateFolderFunction(id, options) {
  try {
    const updatedFolder = await folders.updateFolder(id, options);

    console.log(`Updated folder ${updatedFolder.displayName}:`, updatedFolder);
    return updatedFolder;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "_createdDate": "2023-08-21T09:32:34.000Z",
 *   "_id": "7984b3c5454e4371acbd4f4eedde96bc",
 *   "_updatedDate": "2023-08-21T11:10:51.000Z",
 *   "displayName": "mountains",
 *   "parentFolderId": "103601562ec94214bee61f470b403dd5",
 *   "state": "OK"
 * }
 */
```

### updateFolder (self-managed)
Self-managed 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 updateFolder(_id,folder) {
  const response = await myWixClient.folders.updateFolder(_id,folder);
};
```

---