Skip to content

Content Migration Between Joomla Sites via REST API and DB

Overview

Transfer articles and menus between two Joomla sites without manual work: start with read-only database reconnaissance, then dry-run, and finally publish via REST API. Here is the full sequence of actions.

When to Use This Approach

  • Moving a blog or service section from one site to another;
  • Translating content to another language and publishing on a second site;
  • Cloning menu structure and articles.

I have used this approach in two projects: blog migration and service section migration. Details are in the cases blog migration and DeepSeek-architect.

General Workflow

flowchart TD
    A["Read-only: investigate source"] --> B["Read-only: investigate destination"]
    B --> C["Find duplicates before write"]
    C --> D["Dry-run: migration plan"]
    D --> E{"Human: OK?"}
    E -->|no| D
    E -->|yes| F["Translation and preview"]
    F --> G{"Human: OK?"}
    G -->|no| F
    G -->|yes| H["Write: articles and menus"]
    H --> I["SEO and internal links"]
    I --> J["Report with object IDs"]

Golden rule: read-only first, then write. No changes until you see the full plan.

Step 1. Configuration: Everything in .env

Database addresses, access credentials, and tokens are stored in .env:

# Source — read-only access only
SRC_DB_HOST=...
SRC_DB_NAME=...
SRC_DB_USER=...
SRC_DB_PASSWORD=...

# Destination
DST_DB_HOST=...
DST_DB_NAME=...
DST_DB_USER=...
DST_DB_PASSWORD=...

# Publish via Joomla Web Services
DST_SITE_URL=...
DST_API_TOKEN=...

# Translation via DeepSeek
DEEPSEEK_API_KEY=...
DEEPSEEK_API_URL=https://api.deepseek.com/chat/completions
DEEPSEEK_MODEL=deepseek-chat

Important rules:

  • The source is available only for reading — even a broken script won't change the source site;
  • .env is not published or committed;
  • tokens and passwords are not embedded in the code.

Step 2. Read-only Inventory

Before writing, you need to know what you're working with. Key questions:

  • Are articles in categories or linked to menu items?
  • What are the IDs of the source articles and how do they differ from the IDs on the destination site?
  • Are there objects with the same alias on the destination site?

Example inventory of the source menu — a standard SQL SELECT:

SELECT id, title, alias, path, link
FROM #__menu
WHERE path LIKE 'needed/section/%';

The result will show the structure: which items are parent, which are child, and which articles they link to.

Step 3. Find Duplicates Before Writing

The most valuable part of reconnaissance is finding objects that already exist on the destination site. Otherwise, duplicates will appear during migration.

Typical finding: an article with the required title already exists but is not published (state=0). It can be reused via PATCH, not created anew.

# Check: is there an article with this alias on the destination site?
GET {DST_SITE_URL}/api/index.php/v1/content/articles
Headers: X-Joomla-Token: {DST_API_TOKEN}

If the article is found — update it, not create a copy. This saves time and keeps the database clean.

Step 4. Dry-run: Plan Without Writing

Create a table of actions for each page:

# Page Action
1 Parent Create new
2 Already exists on destination site Reuse (PATCH)
3 Child Create new

Until the plan is approved — no writes. This is a dry-run: a rehearsal without real changes.

Step 5. Publish via Joomla Web Services

Joomla 4+ has a built-in REST API. Main operations:

# Create an article
POST {SITE_URL}/api/index.php/v1/content/articles
Headers: X-Joomla-Token: {TOKEN}
Body: {"title": "...", "articletext": "...", "catid": 2, "language": "*"}

# Update an existing article
PATCH {SITE_URL}/api/index.php/v1/content/articles/{ID}
Body: {"title": "...", "alias": "...", "state": 1}

# Work with menus
GET  {SITE_URL}/api/index.php/v1/menus/site/items
POST {SITE_URL}/api/index.php/v1/menus/site/items
PATCH {SITE_URL}/api/index.php/v1/menus/site/items/{ID}

Check that the API is alive:

import requests

r = requests.get(
    f"{SITE_URL}/api/index.php/v1/content/articles",
    headers={"X-Joomla-Token": TOKEN},
    timeout=30,
)
print(r.status_code)  # 200 — all good

After publishing articles, two tails remain:

  1. Meta tags. If the site uses 4SEO, meta title/description are stored in plugin tables. They can be set directly in the DB or via the plugin API.
  2. Internal links. In the transferred HTML, links to old URLs remain. They need to be remapped to new SEF addresses.

These steps are done after publishing and in a separate run, with a report on each change.

Step 7. Report with Object IDs

After each stage, request a report: which IDs were created, which were updated, which links were remapped. This is the only way to understand that the migration went exactly as planned.

Created articles: 4
Updated articles: 1
Created menu items: 4
Updated menu items: 1

What Not to Do

  • Write to the source. It is read-only.
  • Mass UPDATE without a plan. First one write — check.
  • Create duplicates, if the object already exists on the destination site.
  • Ignore broken links — after migration, they will become 404.

Conclusion

Migration between Joomla sites is not 'export and import', but a sequence: read-only reconnaissance → duplicate search → dry-run → approval → write → meta tags → links. The main benefit is predictability: you know in advance exactly what will change.

See Also