/admin/sync

POST SYNC

Manually trigger a data synchronization from the RAIDA network.

POST /api/admin/sync

Description

The `/admin/sync` endpoint allows administrators to manually trigger a synchronization operation that pulls the latest data from the RAIDA network. This includes user information, server status, and other critical data. The synchronization ensures that the QMail system has the most up-to-date information from all RAIDA servers.

Manual Synchronization

While the QMail system automatically synchronizes data at regular intervals, this endpoint allows you to force an immediate sync operation. This is useful after network disruptions or when you need to ensure data is current before performing critical operations.

Administrative Endpoint

This endpoint may take several seconds to complete depending on network conditions and the number of servers. Ensure you have proper authorization before triggering sync operations.

Request Body

This endpoint does not require a request body. Simply send a POST request to trigger the synchronization.

Response

Returns a 200 OK response with sync results on success, or an error response if the synchronization fails.

Success Response Properties

status string
The operation status. Will be "success" on successful sync, or "error" if sync fails.
users_synced integer
The number of user records that were synchronized.
servers_synced integer
The number of server records that were synchronized.
timestamp string
ISO 8601 timestamp of when the synchronization completed.

Example Success Response (200 OK)

{
  "status": "success",
  "users_synced": 1247,
  "servers_synced": 25,
  "timestamp": "2025-12-21T10:30:45.123Z"
}

Example Error Response

{
  "status": "error",
  "users_synced": 0,
  "servers_synced": 0,
  "timestamp": "2025-12-21T10:30:45.123Z",
  "message": "Failed to connect to RAIDA network. Please check network connectivity."
}

Try It Out

http://localhost:8080/api/admin/sync
Note

This operation may take several seconds to complete. Please be patient while the system synchronizes data from all RAIDA servers.

Examples

JavaScript (async/await)

const API_BASE = 'http://localhost:8080/api';

async function syncFromRAIDA() {
    try {
        console.log('Starting synchronization...');

        const response = await fetch(`${API_BASE}/admin/sync`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            }
        });

        const data = await response.json();

        if (!response.ok) {
            throw new Error(data.message || `HTTP error! status: ${response.status}`);
        }

        console.log(`Sync Status: ${data.status}`);
        console.log(`Users Synced: ${data.users_synced}`);
        console.log(`Servers Synced: ${data.servers_synced}`);
        console.log(`Completed at: ${data.timestamp}`);

        return data;
    } catch (error) {
        console.error('Synchronization failed:', error);
        throw error;
    }
}

// Trigger the sync
syncFromRAIDA()
    .then(result => console.log('Sync completed successfully'))
    .catch(error => console.error('Sync error:', error));

cURL

# Trigger manual synchronization
curl -X POST "http://localhost:8080/api/admin/sync" \
  -H "Content-Type: application/json"

# Expected success response:
# {"status":"success","users_synced":1247,"servers_synced":25,"timestamp":"2025-12-21T10:30:45.123Z"}

Go

package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

const ApiBase = "http://localhost:8080/api"

type SyncResponse struct {
    Status        string `json:"status"`
    UsersSynced   int    `json:"users_synced"`
    ServersSynced int    `json:"servers_synced"`
    Timestamp     string `json:"timestamp"`
    Message       string `json:"message,omitempty"`
}

func syncFromRAIDA() (*SyncResponse, error) {
    url := fmt.Sprintf("%s/admin/sync", ApiBase)

    resp, err := http.Post(url, "application/json", nil)
    if err != nil {
        return nil, err
    }
    defer resp.Body.Close()

    var result SyncResponse
    if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
        return nil, err
    }

    if result.Status == "error" {
        return nil, fmt.Errorf("sync failed: %s", result.Message)
    }

    return &result, nil
}

func main() {
    fmt.Println("Starting synchronization...")

    result, err := syncFromRAIDA()
    if err != nil {
        panic(err)
    }

    fmt.Printf("Status: %s\n", result.Status)
    fmt.Printf("Users Synced: %d\n", result.UsersSynced)
    fmt.Printf("Servers Synced: %d\n", result.ServersSynced)
    fmt.Printf("Completed at: %s\n", result.Timestamp)
}

Related Endpoints

/data/servers

View the current status of all RAIDA servers after synchronization.

/admin/servers/parity

Configure the parity server for redundancy and error recovery.