How to Create and Update Modula Galleries with the REST API

If you want to automate gallery creation in Modula, the good news is that you can do it using the WordPress REST API.

Because Modula stores galleries as a custom post type and images as post meta, you can create galleries, update them, and attach images programmatically instead of doing everything manually in your WordPress admin dashboard.

In this guide, you’ll learn how to:
– create a new Modula gallery
– add images to an existing gallery
– retrieve gallery data through the API


How Modula Stores Galleries

Before working with the API, it helps to understand how Modula stores its data.
Modula galleries are stored as a custom post type: modula-gallery

Gallery images and settings are stored as post meta, including fields such as: modula-images, modulaSettings
In practice, this means you are working with the standard WordPress REST API for the modula-gallery post type, while also sending or reading Modula-specific fields.

Prerequisites

Before you start, make sure you have:
Modula Lite/Free installed and activated
Modula Pro installed if your workflow depends on Pro gallery types
– authentication credentials for protected REST requests
– images already uploaded to the WordPress Media Library if you want to attach them by ID

For authentication, we recommend using Application Passwords.
You can generate one from: Users → Profile → Application Passwords

Security Note
When using the REST API:
– never expose credentials in client-side JavaScript
– never hardcode credentials in public code
– prefer Application Passwords over Basic Auth in production
– restrict API access where possible


Creating a New Gallery

Modula galleries are available through the WordPress REST API under the modula-gallery post type.
To create a new gallery, send a POST request to:

https://yoursite.com/wp-json/wp/v2/modula-gallery

At minimum, you need to provide a title, status, and a gallery type inside modulaSettings:

{
  "title": "My Vacation Gallery",
  "status": "publish",
  "modulaSettings": {
    "type": "grid"
  }
}

Available gallery types: grid, custom-grid, slider, creative-gallery, video, bnb.
If you are not sure which gallery types are available in your current setup, test first on a staging environment. Some types may depend on Pro modules or specific add-ons.

Example: cURL
curl -s -X POST "https://yoursite.com/wp-json/wp/v2/modula-gallery" \
  -u 'your_username:your_application_password' \
  -H 'Content-Type: application/json' \
  -d '{
    "title": "Summer Trip 2026",
    "status": "publish",
    "modulaSettings": { "type": "grid" }
  }'

The response should include the new gallery ID. Save that value, because you’ll need it when adding images.


Adding Images to a Gallery

Images in a Modula gallery are stored as post meta under the key modula-images.
Each image is represented as an object containing at minimum an ID — the WordPress Media Library item  ID.
To add images to an existing gallery, send a POST request to the specific gallery endpoint and include the modulaImages field.

Example: cURL

Replace {GALLERY_ID} with the ID returned when you created the gallery:

curl -s -X POST "https://yoursite.com/wp-json/wp/v2/modula-gallery/{GALLERY_ID}" \
  -u 'your_username:your_application_password' \
  -H 'Content-Type: application/json' \
  -d '{
    "modulaImages": [
      { "id": "101", "title": "Sunset on the beach" },
      { "id": "102", "title": "Mountain view" },
      { "id": "103", "title": "Sea view" }
    ]
  }'

This lets you update the gallery with images that already exist in the Media Library.
Before using this approach in production, confirm that:
– the image IDs exist in the Media Library
– the authenticated user has permission to edit the gallery
– your Modula version exposes the relevant fields as expected through REST

Available Image Object Fields

Each entry inside modulaImages can include more than just the Media Library ID.
In addition to the required ID, you can also pass optional fields that control how the image is displayed or behaves inside the gallery.
Example image object:

{
  "id": "123",
  "title": "Photo Title",
  "caption": "A caption",
  "alt": "Alt text",
  "link": "add-url-here",
  "filters": ""
}

Field reference
id — Required. WordPress Media Library attachment ID.
title — Optional. Displayed as the image title, usually on hover or overlay.
caption — Optional. Adds a caption to the image.
alt — Optional. Alt text for accessibility and SEO.
link — Optional. Custom URL for the image.
filters — Optional. Filter or category tags associated with the image.


Listing and Querying Galleries

You can read galleries using standard GET requests — no authentication required for public galleries:

# List all published galleries
GET https://yoursite.com/wp-json/wp/v2/modula-gallery
 
# Get a specific gallery by ID
GET https://yoursite.com/wp-json/wp/v2/modula-gallery/{GALLERY_ID}

Gallery responses include the modulaSettings and modulaImages fields, so you can inspect both the configuration and images in a single request.


Final Thoughts

If you want to automate gallery creation in Modula from an external service or integration, the REST API gives you a flexible foundation to do it.

This approach is usually the best choice when:
– your logic runs outside WordPress
– you are connecting Modula to another platform
– you want to create or update galleries remotely

Once you have the basics in place, you can build more advanced workflows such as:
– syncing galleries from external systems
– bulk-creating galleries
– assigning images automatically
– integrating gallery creation into custom apps or services

If you’re building on top of WordPress and Modula, this gives you a practical way to manage galleries at scale.

Avatar photo
Andrei Cristea

I love everything WordPress—writing blog posts, exploring plugins, and yes, even hunting down bugs. When I'm not deep in the WordPress world, you'll find me training martial arts, enjoying dark humor, or binge-watching movies and TV series.

Articles: 28