Import & Export

Exportieren Sie Projekte als portable .mpz-Dateien für Backup oder Transfer und importieren Sie sie in andere Mandanten. Verwalten Sie außerdem Projektthumbnails.

Projektpakete (.mpz)

Das .mpz-Format ist ein mindzie Package Zip, das enthält:

  • Projekteinstellungen und Metadaten
  • Alle Datensätze und ihre Konfigurationen
  • Untersuchungen und Notebooks
  • Dashboards und Panels
  • Dateiablagen (Ereignisprotokolle, Anhänge)

Projekt exportieren

GET /api/{tenantId}/project/{projectId}/download

Exportiert das Projekt als .mpz (mindzie Package Zip) Datei.

Pfadparameter

Parameter Typ Erforderlich Beschreibung
tenantId GUID Ja Der Mandanten-Identifier
projectId GUID Ja Das zu exportierende Projekt

Antwort

Gibt einen Binärdatei-Download mit:

  • Content-Type: application/octet-stream
  • Dateiname: {projectName}.mpz

Anwendungsfälle

  • Backup: Erstellen Sie regelmäßige Sicherungen wichtiger Projekte
  • Migration: Verschieben Sie Projekte zwischen Mandanten oder Instanzen
  • Vorlagen: Exportieren Sie ein konfiguriertes Projekt als Vorlage für neue Analysen

Projekt importieren

POST /api/{tenantId}/project/import

Importiert ein Projekt aus einer .mpz-Datei.

Pfadparameter

Parameter Typ Erforderlich Beschreibung
tenantId GUID Ja Der Zielmandant

Anfrage

  • Content-Type: multipart/form-data
  • Dateiparameter: file (die .mpz-Datei)

Einschränkungen

Einschränkung Wert
Maximale Dateigröße 1 GB
Dateiendung Muss .mpz sein
Dateiformat Muss ein gültiger mindzie Projekt-Export sein

Antwort (200 OK)

{
  "success": true,
  "projectId": "99999999-9999-9999-9999-999999999999",
  "projectName": "Imported Project",
  "datasetsImported": 2,
  "investigationsImported": 3,
  "dashboardsImported": 1,
  "message": "Project imported successfully"
}

Antwortfelder

Feld Typ Beschreibung
success boolean Ob der Import erfolgreich war
projectId GUID ID des neu erstellten Projekts
projectName string Name des importierten Projekts
datasetsImported integer Anzahl importierter Datensätze
investigationsImported integer Anzahl importierter Untersuchungen
dashboardsImported integer Anzahl importierter Dashboards
message string Lesbarer Status

Fehlerantworten

Bad Request (400):

{
  "success": false,
  "errorMessage": "Invalid file format. Expected .mpz file."
}

Thumbnail Verwaltung

Projekt-Thumbnails werden in der Projektliste angezeigt und dienen zur visuellen Identifikation.

Thumbnail abrufen

GET /api/{tenantId}/project/{projectId}/thumbnail

Ruft das Thumbnail-Bild des Projekts ab.

Antwort (200 OK)

{
  "projectId": "87654321-4321-4321-4321-210987654321",
  "hasThumbnail": true,
  "base64Image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD..."
}

Antwortfelder

Feld Typ Beschreibung
projectId GUID Projekt-Identifikator
hasThumbnail boolean Ob ein Thumbnail vorhanden ist
base64Image string Base64-codiertes Bild mit Data-URI-Präfix

Thumbnail aktualisieren

POST /api/{tenantId}/project/{projectId}/thumbnail

Aktualisiert das Thumbnail-Bild des Projekts.

Anfrageinhalt

{
  "base64Image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD..."
}

Hinweis: Der Base64-String sollte den Data-URI-Präfix enthalten (z.B. data:image/jpeg;base64, oder data:image/png;base64,).

Antwort (200 OK)

{
  "message": "Thumbnail updated successfully"
}

Thumbnail entfernen

DELETE /api/{tenantId}/project/{projectId}/thumbnail

Entfernt das Thumbnail des Projekts.

Antwort (200 OK)

{
  "message": "Thumbnail removed successfully"
}

Implementierungsbeispiele

cURL

# Projekt in Datei exportieren
curl -X GET "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/project/87654321-4321-4321-4321-210987654321/download" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  --output project_backup.mpz

# Projekt aus Datei importieren
curl -X POST "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/project/import" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -F "file=@project_backup.mpz"

# Thumbnail abrufen
curl -X GET "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/project/87654321-4321-4321-4321-210987654321/thumbnail" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

# Thumbnail aktualisieren (aus Base64-Datei)
curl -X POST "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/project/87654321-4321-4321-4321-210987654321/thumbnail" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"base64Image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg..."}'

# Thumbnail entfernen
curl -X DELETE "https://your-mindzie-instance.com/api/12345678-1234-1234-1234-123456789012/project/87654321-4321-4321-4321-210987654321/thumbnail" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Python

import requests
import base64
from pathlib import Path

TENANT_ID = '12345678-1234-1234-1234-123456789012'
BASE_URL = 'https://your-mindzie-instance.com'

class ProjectExportManager:
    def __init__(self, token):
        self.headers = {
            'Authorization': f'Bearer {token}'
        }

    def export_project(self, project_id, output_path):
        """Exportiert ein Projekt als .mpz-Datei."""
        url = f'{BASE_URL}/api/{TENANT_ID}/project/{project_id}/download'
        response = requests.get(url, headers=self.headers, stream=True)
        response.raise_for_status()

        with open(output_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)

        print(f"Exportiert nach {output_path}")
        return output_path

    def import_project(self, file_path):
        """Importiert ein Projekt aus einer .mpz-Datei."""
        url = f'{BASE_URL}/api/{TENANT_ID}/project/import'

        with open(file_path, 'rb') as f:
            files = {'file': (Path(file_path).name, f, 'application/octet-stream')}
            response = requests.post(url, headers=self.headers, files=files)

        response.raise_for_status()
        result = response.json()

        print(f"Importiert: {result['projectName']}")
        print(f"  Datensätze: {result['datasetsImported']}")
        print(f"  Untersuchungen: {result['investigationsImported']}")
        print(f"  Dashboards: {result['dashboardsImported']}")

        return result

    def get_thumbnail(self, project_id):
        """Ruht das Projekt-Thumbnail als Base64 ab."""
        url = f'{BASE_URL}/api/{TENANT_ID}/project/{project_id}/thumbnail'
        response = requests.get(url, headers=self.headers)
        response.raise_for_status()
        return response.json()

    def set_thumbnail(self, project_id, image_path):
        """Setzt das Projekt-Thumbnail aus einer Bilddatei."""
        url = f'{BASE_URL}/api/{TENANT_ID}/project/{project_id}/thumbnail'

        # Bild lesen und encodieren
        with open(image_path, 'rb') as f:
            image_data = f.read()

        # MIME-Typ bestimmen
        ext = Path(image_path).suffix.lower()
        mime_type = 'image/jpeg' if ext in ['.jpg', '.jpeg'] else 'image/png'

        # Base64 Data URI erstellen
        base64_data = base64.b64encode(image_data).decode('utf-8')
        data_uri = f'data:{mime_type};base64,{base64_data}'

        headers = {**self.headers, 'Content-Type': 'application/json'}
        response = requests.post(url, json={'base64Image': data_uri}, headers=headers)
        response.raise_for_status()

        print(f"Thumbnail für Projekt {project_id} aktualisiert")
        return response.json()

    def remove_thumbnail(self, project_id):
        """Entfernt das Projekt-Thumbnail."""
        url = f'{BASE_URL}/api/{TENANT_ID}/project/{project_id}/thumbnail'
        response = requests.delete(url, headers=self.headers)
        response.raise_for_status()
        return response.json()

# Verwendung
manager = ProjectExportManager('your-auth-token')
project_id = '87654321-4321-4321-4321-210987654321'

# Projekt für Backup exportieren
manager.export_project(project_id, 'my_project_backup.mpz')

# Import in denselben oder anderen Mandanten
result = manager.import_project('my_project_backup.mpz')
new_project_id = result['projectId']

# Thumbnail setzen
manager.set_thumbnail(project_id, 'project_thumbnail.png')

# Thumbnail abrufen
thumbnail = manager.get_thumbnail(project_id)
if thumbnail['hasThumbnail']:
    print("Thumbnail ist vorhanden")

JavaScript/Node.js

const fs = require('fs');
const path = require('path');
const FormData = require('form-data');

const TENANT_ID = '12345678-1234-1234-1234-123456789012';
const BASE_URL = 'https://your-mindzie-instance.com';

class ProjectExportManager {
  constructor(token) {
    this.headers = {
      'Authorization': `Bearer ${token}`
    };
  }

  async exportProject(projectId, outputPath) {
    const url = `${BASE_URL}/api/${TENANT_ID}/project/${projectId}/download`;
    const response = await fetch(url, { headers: this.headers });

    if (!response.ok) {
      throw new Error(`Export fehlgeschlagen: ${response.status}`);
    }

    const buffer = await response.arrayBuffer();
    fs.writeFileSync(outputPath, Buffer.from(buffer));
    console.log(`Exportiert nach ${outputPath}`);
  }

  async importProject(filePath) {
    const url = `${BASE_URL}/api/${TENANT_ID}/project/import`;

    const formData = new FormData();
    formData.append('file', fs.createReadStream(filePath));

    const response = await fetch(url, {
      method: 'POST',
      headers: {
        ...this.headers,
        ...formData.getHeaders()
      },
      body: formData
    });

    if (!response.ok) {
      throw new Error(`Import fehlgeschlagen: ${response.status}`);
    }

    const result = await response.json();
    console.log(`Importiert: ${result.projectName}`);
    return result;
  }

  async setThumbnail(projectId, imagePath) {
    const url = `${BASE_URL}/api/${TENANT_ID}/project/${projectId}/thumbnail`;

    // Bild lesen und encodieren
    const imageBuffer = fs.readFileSync(imagePath);
    const ext = path.extname(imagePath).toLowerCase();
    const mimeType = ext === '.png' ? 'image/png' : 'image/jpeg';
    const base64Data = imageBuffer.toString('base64');
    const dataUri = `data:${mimeType};base64,${base64Data}`;

    const response = await fetch(url, {
      method: 'POST',
      headers: {
        ...this.headers,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ base64Image: dataUri })
    });

    if (!response.ok) {
      throw new Error(`Thumbnail-Aktualisierung fehlgeschlagen: ${response.status}`);
    }

    return await response.json();
  }
}

// Verwendung
const manager = new ProjectExportManager('your-auth-token');

// Exportieren und Importieren
await manager.exportProject('project-id', 'backup.mpz');
const imported = await manager.importProject('backup.mpz');

// Thumbnail setzen
await manager.setThumbnail('project-id', 'thumbnail.png');

Beste Praktiken

  1. Regelmäßige Backups: Planen Sie regelmäßige Exporte wichtiger Projekte
  2. Versionsbenennung: Fügen Sie Daten in Export-Dateinamen ein (z.B. project_2024-01-15.mpz)
  3. Importtests: Testen Sie Importe in einem Nicht-Produktionsmandanten vor der Produktion
  4. Thumbnail-Größe: Halten Sie Thumbnails unter 100KB für schnelles Laden
  5. Thumbnail-Format: Verwenden Sie JPEG für Fotos und PNG für Grafiken mit Transparenz