REST: WordPress Push-Content (/api/wordpress/push-content)
Diese Seite beschreibt den eingehenden REST-Endpunkt des CockpitOS-Dashboards, über den eine registrierte WordPress-Website (z. B. mit dem CockpitOS-Plugin) Shops, Events, News, Angebote, Services und statische Seiten an die zentrale Datenbank senden kann.
Implementierung im Monorepo: apps/dashboard/src/app/api/wordpress/push-content/route.ts
Ersetzen Sie {DASHBOARD_ORIGIN} durch die öffentliche URL Ihrer Dashboard-Instanz (z. B. https://dashboard.example.com). Lokal oft http://localhost:3000.
Überblick
| Aspekt | Details |
|---|---|
| Methode | POST |
| Pfad | /api/wordpress/push-content |
| Authentifizierung | HTTP-Header Authorization: Bearer <apiKey> |
| API-Key | Der Website-API-Key der WordPress-Instanz, wie er in CockpitOS unter WordPress-Verwaltung hinterlegt ist (WordPressWebsite.apiKey in der Datenbank) |
| Content-Type | application/json |
| CORS | Access-Control-Allow-Origin: * (Preflight OPTIONS wird unterstützt) |
Ohne gültigen Key antwortet die API mit 401; wenn kein passender Website-Eintrag existiert, mit 404.
Request-Body
Der Body ist ein JSON-Objekt. Alle Top-Level-Felder sind optional. Sie können beliebige Kombinationen senden (nur News, nur Shops, usw.).
{
"shops": [],
"events": [],
"news": [],
"offers": [],
"services": [],
"pages": []
}
shops (Array)
Pro Eintrag werden folgende Felder ausgewertet (weitere Keys werden ignoriert):
| Feld | Typ | Beschreibung |
|---|---|---|
id | string (optional) | Wenn gesetzt und im gleichen Center vorhanden → Update, sonst Create |
name | string | Pflicht (leer → Eintrag wird übersprungen) |
category | string | Standard: "Sonstige" |
description, floor, location, logo, phone, email, website, openingHours | string oder null | Optional |
status | string | Standard: "Aktiv" |
events (Array)
| Feld | Typ | Beschreibung |
|---|---|---|
id | string (optional) | Update, wenn ID im Center existiert |
title | string | Pflicht |
startDate, endDate | string (ISO) / Datum | Optional; Default: startDate = jetzt, endDate = eine Stunde später |
description, location, image | string oder null | Optional |
status | string | Standard: "Aktiv" |
Intern wird source auf wordpress gesetzt.
news (Array)
| Feld | Typ | Beschreibung |
|---|---|---|
id | string (optional) | Update, wenn ID im Center existiert |
title | string | Pflicht |
excerpt, summary, content, author, category, image | string oder null | Optional |
publishDate | string (ISO) / Datum | Optional; Standard: aktuelles Datum |
status | string | Standard: "Veröffentlicht" |
Intern wird source auf wordpress gesetzt.
offers (Array)
| Feld | Typ | Beschreibung |
|---|---|---|
id | string (optional) | Update, wenn ID im Center existiert |
title | string | Pflicht |
startDate, endDate | string (ISO) / Datum | Optional; Default: endDate = 7 Tage nach startDate |
description, discount, image | string oder null | Optional |
status | string | Standard: "Aktiv" |
Intern wird source auf wordpress gesetzt.
services (Array)
| Feld | Typ | Beschreibung |
|---|---|---|
id | string (optional) | Update, wenn ID im Center existiert |
name | string | Pflicht |
category, description, floor, location, phone, email, website, openingHours | string oder null | Optional |
status | string | Standard: "Aktiv" |
pages (Array)
Statische WordPress-Seiten (z. B. Anfahrt, Hausordnung) für Kontext (z. B. Chatbot). Sie werden nicht als normale CMS-Seiten-Entitäten wie im Website-Tab gespiegelt, sondern in WordPressWebsite.staticPages gespeichert.
| Feld | Typ | Beschreibung |
|---|---|---|
slug | string | |
title | string | |
content | string | Wird auf 10.000 Zeichen gekürzt |
Zusatzlogik: Enthält eine Seite „Öffnungszeiten“ (Erkennung per Titel/Slug), und ist am Center das Feld openingHours noch leer, wird ein gekürzter Text (HTML-Tags entfernt, max. 500 Zeichen) ins Center übernommen.
Response
Erfolg (HTTP 200)
{
"success": true,
"data": {
"summary": {
"shops": 0,
"events": 0,
"news": 0,
"offers": 0,
"services": 0
},
"errors": ["optional: Fehlermeldungen pro Datensatz"]
},
"message": "Push-Content verarbeitet"
}
errors fehlt, wenn keine Einzelfehler aufgetreten sind. Bei teilweisem Fehlschlag können einzelne Datensätze fehlschlagen, andere werden trotzdem verarbeitet.
Die zugehörige WordPress-Website erhält ein aktualisiertes lastSync; bei Fehlern kann lastError (gekürzt) gesetzt werden.
Fehler
| HTTP | Bedeutung |
|---|---|
| 401 | Kein Authorization: Bearer-Header |
| 404 | Keine WordPressWebsite mit diesem API-Key |
| 400 | Ungültiges JSON |
| 500 | Unerwarteter Serverfehler |
Beispiel: curl
curl -sS -X POST "${DASHBOARD_ORIGIN}/api/wordpress/push-content" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_WORDPRESS_WEBSITE_API_KEY" \
-d '{
"news": [
{
"title": "Beispielmeldung",
"excerpt": "Kurztext",
"content": "<p>HTML-Inhalt</p>",
"status": "Veröffentlicht"
}
]
}'
Verwandte Endpunkte
- Website registrieren / anbinden:
POST /api/wordpress/websites(Dashboard-Session oder Abgleich API-Key im Header mit Body – sieheapps/dashboard/src/app/api/wordpress/websites/route.ts). - Einbettungs-Konfiguration (öffentlich mit Website-Key):
GET /api/wordpress/embed-config– siehe Kommentar inapps/dashboard/src/app/api/wordpress/embed-config/route.ts. - Ausgehende Benachrichtigungen an externe Systeme (nicht zum Schreiben ins Cockpit): Webhooks – siehe Integration & Webhooks.
Weitere API-Dokumentation
Eine vollständige OpenAPI-Referenz aller Dashboard-Endpunkte ist weiterhin in Planung; dieser Endpunkt ist derzeit die zentral dokumentierte Schnittstelle für Inhalte von WordPress ins Cockpit.
Nutzungsstatistik: Seitenaufrufe werden anonymisiert erfasst. Im Umami-Dashboard nach diesem Pfad filtern: /en/developer-guide/api-wordpress-push-content