createGalleryItem( )
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 theimageInfo
parameter currently only supports the Wix media URL.
Override permissions
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
Gallery ID.
Media item to create.
Returns
Created media item.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time the item was created.
Item ID.
Date and time the item was last updated.
Item description.
Details about the image.
Link from the item. You can link to Wix sites or external URLs.
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.
Item tags.
Details about the text file.
Item title.
Supported values:
'IMAGE'
'TEXT'
'UNDEFINED'
'VIDEO'
Details about the video.
Was this helpful?
Create a gallery item
1import { proGallery } from 'wix-pro-gallery-backend';23/* 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 */2223export async function myCreateGalleryItemFunction(galleryId, item) {24 try {25 const createdGalleryItem = await proGallery.createGalleryItem(galleryId, item);2627 const id = createdGalleryItem._id;28 const title = createdGalleryItem.title;2930 console.log('Success! Created the gallery item:', createdGalleryItem);31 return createdGalleryItem;32 } catch (error) {33 console.error(error);34 // Handle the error35 }36}3738/* 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 */