Search.../

updateGallery( )

Developer Preview

Updates a gallery.

Description

The updateGallery() function returns a Promise that resolves to an updated gallery. Only the fields in the gallery object parameter can be updated. Specify which fields to update. Unspecified fields remain the same.

Important: When updating image items in your gallery, the images must be uploaded to the Wix Media Manager first as the imageInfo parameter currently only supports the Wix media URL.

This function is restricted and only runs if you elevate permissions using the wix-auth elevate() function.

Warning: Elevating a function allows it to be called by any site visitor. Exercise caution to prevent security vulnerabilities.

Syntax

function updateGallery(_id: string, gallery: UpdateGallery): Promise<Gallery>

updateGallery Parameters

NAME
TYPE
DESCRIPTION
_id
string

ID of the gallery to update.

gallery
UpdateGallery

The information for the gallery being updated.

Returns

Updated gallery.

Return Type:

Promise<
Gallery
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the gallery was created.

_id
string

Gallery ID.

items
Array<
Item
>

Media items in the gallery.

name
string

Gallery name.

sortOrder
number

Index that determines which position a gallery is displayed on the site.

Note: If you assign the same sort order index to more than one gallery, the function fails.

totalItems
number

Total number of items in the gallery.

Was this helpful?

Update a gallery

Copy Code
1import { proGallery } from 'wix-pro-gallery-backend';
2
3/* Sample _id value: '10874ccf-5867-4225-9550-3885079bad66'
4 *
5 * Sample gallery value:
6 * {
7 * "name": "New Name",
8 * "sortOrder": 420
9 * }
10 */
11export async function myUpdateGalleryFunction(_id, gallery) {
12 try {
13 const updatedGallery = await proGallery.updateGallery(_id, gallery);
14
15 const name = updatedGallery.name;
16 const sortOrder = updatedGallery.sortOrder;
17
18 console.log('Success! Updated the gallery:', updatedGallery);
19 return updatedGallery;
20 } catch (error) {
21 console.error(error);
22 // Handle the error
23 }
24}
25
26/* Promise resolves to:
27 * {
28 * "_createdDate": "Mon Feb 08 2021 13:44:37",
29 * "_id":"10874ccf-5867-4225-9550-3885079bad66",
30 * "items": [
31 * {
32 * "_createdDate": Tue Mar 30 2021 15:23:22,
33 * "_id": "534264c7-0c61-45ce-b414-891aacadf4c2",
34 * "_updatedDate": Tue Mar 30 2021 15:23:22,
35 * "description": "This is the first item in my gallery.",
36 * "sortOrder": 1657439075188
37 * "title": "Item 1"
38 * "type": "IMAGE",
39 * "image": {
40 * "imageInfo": "wix:image://v1/38939f9568z222d6avc6285c9ac1e9129.jpg/38939f9568z222d6avc6285c9ac1e9129.jpg#originWidth=200&originHeight=199"
41 * }
42 * },
43 * {
44 * "_createdDate": Sun Jul 03 2022 12:05:15,
45 * "_id": "4507a07b-ab93-4326-a222-6d0bd8da0625",
46 * "_updatedDate": Tues Jul 05 2022 10:25:45
47 * "description": "This is the second item in my gallery.",
48 * "sortOrder": 1857439076299
49 * "title": "Item 2"
50 * "type": "IMAGE",
51 * "image": {
52 * "imageInfo": "wix:image://v1/25139f9568b74d8aac6286c9ac1e8186.jpg/25139f9568b74d8aac6286c9ac1e8186.jpg#originWidth=4000&originHeight=2667"
53 * }
54 * }
55 * ],
56 * "name": "New Name",
57 * "sortOrder": "420",
58 * "totalItems": 2
59 * }
60 */
61