This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Creates a media item in a specified gallery.
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.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function createGalleryItem(
galleryId: string,
item: Item,
options: CreateGalleryItemOptions,
): Promise<Item>;
Gallery ID.
Media item to create.
import { proGallery } from "wix-pro-gallery-backend";
/* Sample galleryId value: 'af5c3670-9b0f-4d86-b3b9-19fe62006c39'
*
* Sample item value:
* {
* "description": "New image item",
* "title": "My first gallery item",
* "tags": {
* "values": ["ball","sea","beach"]
* },
* "image": {
* "type": "WIX_MEDIA",
* "imageInfo": "wix:image://v1/9e6ea4_650d8cd45f7545c4b39178feb0ee8c70~mv2.jpg/300.jpg#originWidth=200&originHeight=300"
* },
* "link": {
* "text": 'Click here for more info.',
* "url": 'https://www.wix.com/about/us'
* }
* };
*/
export async function myCreateGalleryItemFunction(galleryId, item) {
try {
const createdGalleryItem = await proGallery.createGalleryItem(
galleryId,
item,
);
const id = createdGalleryItem._id;
const title = createdGalleryItem.title;
console.log("Success! Created the gallery item:", createdGalleryItem);
return createdGalleryItem;
} catch (error) {
console.error(error);
// Handle the error
}
}
/* Promise resolves to:
* {
* "_createdDate": "Mon Feb 08 2021 13:44:37",
* "_id": "10874ccf-5867-4225-9550-3885079bad66",
* "_updatedDate": Mon Feb 08 2021 13:44:37,
* "description": "This is the first item in my gallery.",
* "image": {
* "imageInfo": "wix:image://v1/38939f9568z222d6avc6285c9ac1e9129.jpg/38939f9568z222d6avc6285c9ac1e9129.jpg#originWidth=200&originHeight=199"
* },
* "link": {
* "text": 'Click here for more info.',
* "url": 'https://www.wix.com/about/us'
* },
* "sortOrder": 1657439075188,
* "tags": {
* "values": ["ball","sea","beach"]
* },
* "title": "My first gallery item",
* "type": "IMAGE"
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.