Search.../

createGalleryItem( )

Developer Preview

Creates a media item in a specified gallery.

Description

The createGalleryItem() function returns a Promise that resolves to a newly-created gallery item after it has successfully been created.

Important: When creating 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 createGalleryItem(galleryId: string, item: Item): Promise<Item>

createGalleryItem Parameters

NAME
TYPE
DESCRIPTION
galleryId
string

Gallery ID.

item
Item

Media item to create.

Returns

Created media item.

Return Type:

Promise<
Item
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the item was created.

_id
string

Item ID.

_updatedDate
Date

Date and time the item was last updated.

description
string

Item description.

image
Image

Details about the image.

link
Link

Link from the item. You can link to Wix sites or external URLs.

sortOrder
number

Index that determines which position a media item is displayed in the gallery.

Default: Epoch timestamp.

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

tags
Tags

Item tags.

text
Text

Details about the text file.

title
string

Item title.

type
string

Supported values:

  • 'IMAGE'
  • 'TEXT'
  • 'UNDEFINED'
  • 'VIDEO'
video
Video

Details about the video.

Was this helpful?

Create a gallery item

Copy Code
1import { proGallery } from 'wix-pro-gallery-backend';
2
3/* Sample galleryId value: 'af5c3670-9b0f-4d86-b3b9-19fe62006c39'
4 *
5 * Sample item value:
6 * {
7 * "description": "New image item",
8 * "title": "My first gallery item",
9 * "tags": {
10 * "values": ["ball","sea","beach"]
11 * },
12 * "image": {
13 * "type": "WIX_MEDIA",
14 * "imageInfo": "wix:image://v1/9e6ea4_650d8cd45f7545c4b39178feb0ee8c70~mv2.jpg/300.jpg#originWidth=200&originHeight=300"
15 * },
16 * "link": {
17 * "text": 'Click here for more info.',
18 * "url": 'https://www.wix.com/about/us'
19 * }
20 * };
21 */
22
23export async function myCreateGalleryItemFunction(galleryId, item) {
24 try {
25 const createdGalleryItem = await proGallery.createGalleryItem(galleryId, item);
26
27 const id = createdGalleryItem._id;
28 const title = createdGalleryItem.title;
29
30 console.log('Success! Created the gallery item:', createdGalleryItem);
31 return createdGalleryItem;
32 } catch (error) {
33 console.error(error);
34 // Handle the error
35 }
36}
37
38/* Promise resolves to:
39 * {
40 * "_createdDate": "Mon Feb 08 2021 13:44:37",
41 * "_id": "10874ccf-5867-4225-9550-3885079bad66",
42 * "_updatedDate": Mon Feb 08 2021 13:44:37,
43 * "description": "This is the first item in my gallery.",
44 * "image": {
45 * "imageInfo": "wix:image://v1/38939f9568z222d6avc6285c9ac1e9129.jpg/38939f9568z222d6avc6285c9ac1e9129.jpg#originWidth=200&originHeight=199"
46 * },
47 * "link": {
48 * "text": 'Click here for more info.',
49 * "url": 'https://www.wix.com/about/us'
50 * },
51 * "sortOrder": 1657439075188,
52 * "tags": {
53 * "values": ["ball","sea","beach"]
54 * },
55 * "title": "My first gallery item",
56 * "type": "IMAGE"
57 * }
58 */