Inhaltsverzeichnis

Coolify API Guide - Automatisches Deployment

Diese Anleitung beschreibt die Nutzung der Coolify API für automatisierte Deployments der Telegram-Bots.

Übersicht

Coolify Instanz: https://app.coolify.io API Version: v1 Authentifizierung: Bearer Token

Authentifizierung

API Token

Das API Token wird in den Benutzereinstellungen von Coolify generiert:

  1. Einloggen auf https://app.coolify.io
  2. Settings → API
  3. „Generate New Token„ klicken
  4. Token kopieren und sicher speichern
  5. Token niemals öffentlich teilen!

API Requests

Alle API-Requests benötigen den Header:

Authorization: Bearer $COOLIFY_API_TOKEN
Content-Type: application/json

Hinweis: Das Token sollte als Umgebungsvariable ($COOLIFY_API_TOKEN) gespeichert werden, niemals hardcoded.

Wichtige Endpoints

1. Projekt-Übersicht

GET /api/v1/projects

Beispiel:

curl -s "https://app.coolify.io/api/v1/projects" \
  -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
  -H "Content-Type: application/json"

Response:

[
  {
    "id": 1038,
    "uuid": "bso4sss",
    "name": "Anti Spam ohne Vornamenprüfung"
  }
]

2. Application Deploy

POST /api/v1/applications/{uuid}/restart

Beispiel - AntiSpam-ohneVorname:

# Application UUID: x4wco4k
curl -s -X POST \
  "https://app.coolify.io/api/v1/applications/x4wco4k/restart" \
  -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
  -H "Content-Type: application/json"

Response:

{
  "message": "Restart request queued",
  "deployment_uuid": "..."
}

3. Deployment Status prüfen

GET /api/v1/deployments/{uuid}

Beispiel:

curl -s \
  "https://app.coolify.io/api/v1/deployments/DEPLOYMENT_UUID" \
  -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
  -H "Content-Type: application/json" | \
  python3 -m json.tool

Wichtige Application UUIDs

Bot Application UUID Projekt ID
Anti Spam ohne Vornamenprüfung x4wco4k 1038
AntiSpamBot Recode V2.0 uokcw80 -
AntiSpamMessageScanBot wgcs8ss -
Anti Deleted Account System bsosk48 834

Eigene UUIDs finden:

curl -s "https://app.coolify.io/api/v1/applications" \
  -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
  -H "Content-Type: application/json" | \
  python3 -c "import sys,json; [print(f\"{a['name']}: {a['uuid']}\") for a in json.load(sys.stdin)]"

Automatisierung mit Git Webhooks

Gitea Webhook einrichten

URL: https://git.thepain.dev/ThePain/AntiSpam-ohneVorname/settings/hooks

Konfiguration:

  1. Target URL: https://app.coolify.io/api/v1/applications/x4wco4k/restart
  2. HTTP Method: POST
  3. Content Type: application/json
  4. Events: Push Events
  5. Branch Filter: main
  6. Is Active: ✅ Ja

Wichtig: Der Webhook benötigt KEIN Bearer Token, da Coolify den Request intern verarbeitet.

Shell Script für manuelles Deploy

#!/bin/bash
# deploy-bot.sh - Manuelles Deployment eines Bots
# Benötigt: COOLIFY_API_TOKEN als Umgebungsvariable
 
APPLICATION_UUID="$1"  # z.B. x4wco4k
 
if [ -z "$COOLIFY_API_TOKEN" ]; then
    echo "❌ Fehler: COOLIFY_API_TOKEN nicht gesetzt"
    echo "export COOLIFY_API_TOKEN='dein-token-hier'"
    exit 1
fi
 
if [ -z "$APPLICATION_UUID" ]; then
    echo "Usage: $0 <application-uuid>"
    echo "Beispiel: $0 x4wco4k"
    exit 1
fi
 
echo "Starting deployment for $APPLICATION_UUID..."
 
RESPONSE=$(curl -s -X POST \
    "https://app.coolify.io/api/v1/applications/$APPLICATION_UUID/restart" \
    -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
    -H "Content-Type: application/json")
 
DEPLOYMENT_UUID=$(echo $RESPONSE | python3 -c "import sys,json; print(json.load(sys.stdin)['deployment_uuid'])")
echo "Deployment queued: $DEPLOYMENT_UUID"
 
# Warte auf Abschluss (optional)
echo "Warte auf Deployment..."
for i in {1..30}; do
    STATUS=$(curl -s \
        "https://app.coolify.io/api/v1/deployments/$DEPLOYMENT_UUID" \
        -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
        -H "Content-Type: application/json" | \
        python3 -c "import sys,json; print(json.load(sys.stdin)['status'])")
 
    echo "Status: $STATUS"
 
    if [ "$STATUS" = "finished" ]; then
        echo "✅ Deployment erfolgreich!"
        exit 0
    elif [ "$STATUS" = "failed" ]; then
        echo "❌ Deployment fehlgeschlagen!"
        exit 1
    fi
 
    sleep 5
done
 
echo "⚠️ Timeout - prüfe manuell in Coolify Dashboard"

Fehlerbehebung

401 Unauthorized

  1. Token ist abgelaufen → Neu generieren in Coolify Settings
  2. Token falsch kopiert → Nochmal prüfen
  3. Umgebungsvariable nicht gesetzt → export COOLIFY_API_TOKEN=…

404 Not Found

  1. Application UUID falsch → Mit /api/v1/applications prüfen
  2. Projekt existiert nicht mehr

Deployment Failed

  1. Logs in Coolify Dashboard prüfen
  2. Häufige Ursachen:
    • Git nicht erreichbar
    • Docker Build Fehler
    • Environment Variables fehlen

Sicherheitshinweise

Token-Schutz

  1. Niemals das Token im Code hardcoden
  2. Niemals das Token in öffentlichen Repositories committen
  3. Niemals das Token in öffentlichen Wikis posten
  4. Verwende immer Umgebungsvariablen
  5. Lokal: export COOLIFY_API_TOKEN=“…„ in ~/.bashrc oder ~/.zshrc
  6. CI/CD: Verwende Secrets/Environment Variables

Token erneuern

Falls das Token kompromittiert wurde:

1. In Coolify: Settings → API → Token löschen
2. Neuen Token generieren
3. Alte Umgebungsvariablen aktualisieren

Letzte Aktualisierung: 2026-02-17
Autor: Klaus 🦞
Hinweis: Diese Anleitung enthält keine sensible Daten. Token müssen lokal gesetzt werden.