Page cover

MetaGallery: Creating Virtual Galleries

1.1 MetaGallery Overview

MetaGallery tool within CapsureLabs enables creators to design, showcase, and manage virtual galleries in Web3-compatible metaverses. This documentation covers how to interact with MetaGallery APIs to create, configure, and update virtual galleries, with examples demonstrating typical API requests for integrating galleries into decentralized environments.


Creating and Configuring Galleries

A new gallery can be created via the POST /api/v1/galleries endpoint. Attributes like name, description, owner, and layout can be configured during creation.

Adding NFTs and Art Assets

Each gallery allows for the addition of NFT assets by linking them through IPFS, Arweave, or another decentralized storage provider.

MetaGallery supports various layout templates. Set layout and theme preferences by updating gallery properties through API requests.


POST /api/v1/galleries
Content-Type: application/json
Authorization: Bearer {token}

Request Body

{
  "name": "My Virtual Art Gallery",
  "description": "A curated collection of digital art.",
  "owner": "0x123...abc",  // Owner's Ethereum address
  "layout": "modern",
  "permissions": "public"
}

Response

{
  "galleryId": "gallery_001",
  "status": "created",
  "link": "https://metagallery.capsurelabs.com/gallery_001"
}
POST /api/v1/galleries/{galleryId}/artwork
Content-Type: application/json
Authorization: Bearer {token}

Request Body

{
  "artworkId": "nft_045",
  "position": { "x": 1, "y": 0, "z": 3 },
  "size": "large",
  "metadata": "ipfs://QmExampleHash"
}

Response

{
  "status": "success",
  "message": "Artwork added to gallery",
  "artworkId": "nft_045"
}
PUT /api/v1/galleries/{galleryId}/layout
Content-Type: application/json
Authorization: Bearer {token}

Request Body

{
  "layout": "abstract",
  "theme": "dark"
}

Response

{
  "status": "success",
  "message": "Gallery layout updated"
}
DELETE /api/v1/galleries/{galleryId}/artwork/{artworkId}
Content-Type: application/json
Authorization: Bearer {token}

Response

{
  "status": "success",
  "message": "Artwork removed from gallery"
}

1.4 Code for API Integration

Using the requests library in Python, this example demonstrates creating a gallery, adding artwork, and updating gallery settings.

import requests

API_URL = "https://metagallery.capsurelabs.com/api/v1"
TOKEN = "your_api_token_here"  # Replace with your actual API token

headers = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json"
}

# 1. Create a New Gallery
def create_gallery():
    url = f"{API_URL}/galleries"
    data = {
        "name": "My Virtual Art Gallery",
        "description": "A curated collection of digital art.",
        "owner": "0x123...abc",
        "layout": "modern",
        "permissions": "public"
    }
    response = requests.post(url, headers=headers, json=data)
    print("Create Gallery Response:", response.json())

# 2. Add Artwork to the Gallery
def add_artwork(gallery_id, artwork_id, metadata_url):
    url = f"{API_URL}/galleries/{gallery_id}/artwork"
    data = {
        "artworkId": artwork_id,
        "position": {"x": 1, "y": 0, "z": 3},
        "size": "large",
        "metadata": metadata_url
    }
    response = requests.post(url, headers=headers, json=data)
    print("Add Artwork Response:", response.json())

# 3. Update Gallery Layout
def update_layout(gallery_id, layout, theme):
    url = f"{API_URL}/galleries/{gallery_id}/layout"
    data = {"layout": layout, "theme": theme}
    response = requests.put(url, headers=headers, json=data)
    print("Update Layout Response:", response.json())

# Example execution
gallery_id = "gallery_001"
artwork_id = "nft_045"
metadata_url = "ipfs://QmExampleHash"

create_gallery()
add_artwork(gallery_id, artwork_id, metadata_url)
update_layout(gallery_id, "abstract", "dark")

Dependencies

To use this code, install the requests library:

pip install requests

1.5 Best Practices and Considerations

  1. IPFS Storage: Store large media files on IPFS or another decentralized storage and use the metadata link in API requests for better performance and data integrity.

  2. Token-Based Access: Utilize Bearer tokens for secure API calls. Regularly update and manage tokens to maintain security.

  3. Optimized Layout Selection: Choose the layout based on the gallery size and audience. Layout adjustments impact performance, especially for galleries with numerous items.

  4. Batch Operations: For galleries with a large number of assets, consider batch updates to minimize API calls and reduce latency.

  5. Error Handling: Implement error handling to manage API response errors, especially for rate limiting and access control issues.

Last updated