REST API Reference

In questa pagina

EmDash espone un’API REST all’indirizzo /_emdash/api/ per la gestione dei contenuti, l’upload dei media e le operazioni sullo schema.

Autenticazione

Le richieste API richiedono l’autenticazione tramite token Bearer:

Authorization: Bearer <token>

Genera i token tramite l’interfaccia admin o in modo programmatico.

Formato delle risposte

Tutte le risposte seguono un formato coerente:

// Success
{
  "success": true,
  "data": { ... }
}

// Error
{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable message",
    "details": { ... }
  }
}

Endpoint dei contenuti

Elencare contenuti

GET /_emdash/api/content/:collection

Parametri

ParametroTipoDescrizione
collectionstringSlug della collezione (path)
cursorstringCursore di paginazione (query)
limitnumberElementi per pagina (query, predefinito: 50)
statusstringFiltra per stato (query)
orderBystringCampo per l’ordinamento (query)
orderstringDirezione ordinamento: asc o desc (query)

Risposta

{
  "success": true,
  "data": {
    "items": [
      {
        "id": "01HXK5MZSN...",
        "type": "posts",
        "slug": "hello-world",
        "data": { "title": "Hello World", ... },
        "status": "published",
        "createdAt": "2025-01-24T12:00:00Z",
        "updatedAt": "2025-01-24T12:00:00Z"
      }
    ],
    "nextCursor": "eyJpZCI6..."
  }
}

Ottenere un contenuto

GET /_emdash/api/content/:collection/:id

Risposta

{
  "success": true,
  "data": {
    "item": {
      "id": "01HXK5MZSN...",
      "type": "posts",
      "slug": "hello-world",
      "data": { "title": "Hello World", ... },
      "status": "published",
      "createdAt": "2025-01-24T12:00:00Z",
      "updatedAt": "2025-01-24T12:00:00Z"
    }
  }
}

Creare un contenuto

POST /_emdash/api/content/:collection
Content-Type: application/json

Corpo della richiesta

{
  "data": {
    "title": "New Post",
    "content": [...]
  },
  "slug": "new-post",
  "status": "draft"
}

Risposta

{
  "success": true,
  "data": {
    "item": { ... }
  }
}

Aggiornare un contenuto

PUT /_emdash/api/content/:collection/:id
Content-Type: application/json

Corpo della richiesta

{
	"data": {
		"title": "Updated Title"
	},
	"status": "published"
}

Eliminare un contenuto

DELETE /_emdash/api/content/:collection/:id

Risposta

{
	"success": true,
	"data": {
		"success": true
	}
}

Endpoint dei media

Elencare media

GET /_emdash/api/media

Parametri

ParametroTipoDescrizione
cursorstringCursore di paginazione
limitnumberElementi per pagina (predefinito: 20)
mimeTypestringFiltra per prefisso tipo MIME

Risposta

{
	"success": true,
	"data": {
		"items": [
			{
				"id": "01HXK5MZSN...",
				"filename": "photo.jpg",
				"mimeType": "image/jpeg",
				"size": 102400,
				"width": 1920,
				"height": 1080,
				"url": "https://cdn.example.com/photo.jpg",
				"createdAt": "2025-01-24T12:00:00Z"
			}
		],
		"nextCursor": "eyJpZCI6..."
	}
}

Ottenere un media

GET /_emdash/api/media/:id

Creare un media

POST /_emdash/api/media
Content-Type: application/json

Corpo della richiesta

{
	"filename": "photo.jpg",
	"mimeType": "image/jpeg",
	"size": 102400,
	"width": 1920,
	"height": 1080,
	"storageKey": "uploads/photo.jpg"
}

Aggiornare un media

PUT /_emdash/api/media/:id
Content-Type: application/json

Corpo della richiesta

{
	"alt": "Photo description",
	"caption": "Photo caption"
}

Eliminare un media

DELETE /_emdash/api/media/:id

Ottenere il file media

GET /_emdash/api/media/file/:key

Serve il contenuto effettivo del file. Solo per lo storage locale.

Endpoint delle revisioni

Elencare revisioni

GET /_emdash/api/content/:collection/:entryId/revisions

Parametri

ParametroTipoDescrizione
limitnumberRevisioni massime da restituire (predefinito: 50)

Risposta

{
  "success": true,
  "data": {
    "items": [
      {
        "id": "01HXK5MZSN...",
        "collection": "posts",
        "entryId": "01HXK5MZSN...",
        "data": { ... },
        "createdAt": "2025-01-24T12:00:00Z"
      }
    ],
    "total": 5
  }
}

Ottenere una revisione

GET /_emdash/api/revisions/:revisionId

Ripristinare una revisione

POST /_emdash/api/revisions/:revisionId/restore

Ripristina il contenuto allo stato di questa revisione e crea una nuova revisione.

Endpoint dello schema

Elencare collezioni

GET /_emdash/api/schema/collections

Risposta

{
	"success": true,
	"data": {
		"items": [
			{
				"id": "01HXK5MZSN...",
				"slug": "posts",
				"label": "Posts",
				"labelSingular": "Post",
				"supports": ["drafts", "revisions", "preview"]
			}
		]
	}
}

Ottenere una collezione

GET /_emdash/api/schema/collections/:slug

Parametri

ParametroTipoDescrizione
includeFieldsbooleanIncludi le definizioni dei campi (query)

Creare una collezione

POST /_emdash/api/schema/collections
Content-Type: application/json

Corpo della richiesta

{
	"slug": "products",
	"label": "Products",
	"labelSingular": "Product",
	"description": "Product catalog",
	"supports": ["drafts", "revisions"]
}

Aggiornare una collezione

PATCH /_emdash/api/schema/collections/:slug
Content-Type: application/json

Eliminare una collezione

DELETE /_emdash/api/schema/collections/:slug

Parametri

ParametroTipoDescrizione
forcebooleanElimina anche se la collezione ha contenuti (query)

Elencare campi

GET /_emdash/api/schema/collections/:slug/fields

Creare un campo

POST /_emdash/api/schema/collections/:slug/fields
Content-Type: application/json

Corpo della richiesta

{
	"slug": "price",
	"label": "Price",
	"type": "number",
	"required": true,
	"validation": {
		"min": 0
	}
}

Aggiornare un campo

PATCH /_emdash/api/schema/collections/:collectionSlug/fields/:fieldSlug
Content-Type: application/json

Eliminare un campo

DELETE /_emdash/api/schema/collections/:collectionSlug/fields/:fieldSlug

Riordinare i campi

POST /_emdash/api/schema/collections/:slug/fields/reorder
Content-Type: application/json

Corpo della richiesta

{
	"fieldSlugs": ["title", "content", "author", "publishedAt"]
}

Esportazione dello schema

Esporta schema (JSON)

GET /_emdash/api/schema
Accept: application/json

Esporta schema (TypeScript)

GET /_emdash/api/schema?format=typescript
Accept: text/typescript

Restituisce le interfacce TypeScript per tutte le collezioni.

Endpoint dei plugin

Elencare plugin

GET /_emdash/api/plugins

Ottenere un plugin

GET /_emdash/api/plugins/:pluginId

Abilitare un plugin

POST /_emdash/api/plugins/:pluginId/enable

Disabilitare un plugin

POST /_emdash/api/plugins/:pluginId/disable

Codici di errore

CodiceStato HTTPDescrizione
NOT_FOUND404Risorsa non trovata
VALIDATION_ERROR400Dati di input non validi
UNAUTHORIZED401Token mancante o non valido
FORBIDDEN403Permessi insufficienti
CONTENT_LIST_ERROR500Errore nell’elenco contenuti
CONTENT_CREATE_ERROR500Errore nella creazione contenuto
CONTENT_UPDATE_ERROR500Errore nell’aggiornamento contenuto
CONTENT_DELETE_ERROR500Errore nell’eliminazione contenuto
MEDIA_LIST_ERROR500Errore nell’elenco media
MEDIA_CREATE_ERROR500Errore nella creazione media
SCHEMA_ERROR400Operazione schema fallita
DUPLICATE_SLUG409Lo slug esiste già
RESERVED_SLUG400Lo slug è riservato

Endpoint di ricerca

Ricerca globale

GET /_emdash/api/search?q=hello+world

Parametri

ParametroTipoDescrizione
qstringQuery di ricerca (obbligatorio)
collectionsstringSlug delle collezioni separati da virgola
statusstringFiltra per stato (predefinito: published)
limitnumberRisultati massimi (predefinito: 20)
cursorstringCursore di paginazione

Risposta

{
  "results": [
    {
      "collection": "posts",
      "id": "01HXK5MZSN...",
      "slug": "hello-world",
      "title": "Hello World",
      "snippet": "...this is a <mark>hello</mark> <mark>world</mark> example...",
      "score": 0.95
    }
  ],
  "nextCursor": "eyJvZmZzZXQiOjIwfQ"
}

Suggerimenti di ricerca

GET /_emdash/api/search/suggest?q=hel&limit=5

Restituisce titoli corrispondenti per prefisso per l’autocompletamento.

Ricostruire l’indice di ricerca

POST /_emdash/api/search/rebuild

Ricostruisce l’indice FTS per tutte o specifiche collezioni.

Statistiche di ricerca

GET /_emdash/api/search/stats

Restituisce il conteggio dei documenti indicizzati per collezione.

Endpoint delle sezioni

Elencare sezioni

GET /_emdash/api/sections
GET /_emdash/api/sections?source=theme
GET /_emdash/api/sections?search=newsletter

Ottenere una sezione

GET /_emdash/api/sections/:slug

Creare una sezione

POST /_emdash/api/sections
Content-Type: application/json

{
  "slug": "my-section",
  "title": "My Section",
  "keywords": ["keyword1"],
  "content": [...]
}

Aggiornare una sezione

PUT /_emdash/api/sections/:slug

Eliminare una sezione

DELETE /_emdash/api/sections/:slug

Endpoint delle impostazioni

Ottenere tutte le impostazioni

GET /_emdash/api/settings

Aggiornare le impostazioni

POST /_emdash/api/settings
Content-Type: application/json

{
  "siteTitle": "My Site",
  "tagline": "A great site",
  "postsPerPage": 10
}

Endpoint dei menu

Elencare menu

GET /_emdash/api/menus

Ottenere un menu

GET /_emdash/api/menus/:name

Creare un menu

POST /_emdash/api/menus
Content-Type: application/json

{
  "name": "footer",
  "label": "Footer Navigation"
}

Aggiornare un menu

PUT /_emdash/api/menus/:name

Eliminare un menu

DELETE /_emdash/api/menus/:name

Aggiungere una voce menu

POST /_emdash/api/menus/:name/items
Content-Type: application/json

{
  "type": "page",
  "referenceCollection": "pages",
  "referenceId": "page_about",
  "label": "About Us"
}

Riordinare le voci menu

POST /_emdash/api/menus/:name/reorder
Content-Type: application/json

{
  "items": [
    { "id": "item_1", "parentId": null, "sortOrder": 0 },
    { "id": "item_2", "parentId": null, "sortOrder": 1 },
    { "id": "item_3", "parentId": "item_2", "sortOrder": 0 }
  ]
}

Endpoint delle tassonomie

Elencare definizioni delle tassonomie

GET /_emdash/api/taxonomies

Creare una tassonomia

POST /_emdash/api/taxonomies
Content-Type: application/json

{
  "name": "genre",
  "label": "Genres",
  "labelSingular": "Genre",
  "hierarchical": true,
  "collections": ["books", "movies"]
}

Elencare termini

GET /_emdash/api/taxonomies/:name/terms

Creare un termine

POST /_emdash/api/taxonomies/:name/terms
Content-Type: application/json

{
  "slug": "tutorials",
  "label": "Tutorials",
  "parentId": "term_abc",
  "description": "How-to guides"
}

Aggiornare un termine

PUT /_emdash/api/taxonomies/:name/terms/:slug

Eliminare un termine

DELETE /_emdash/api/taxonomies/:name/terms/:slug

Impostare i termini di una voce

POST /_emdash/api/content/:collection/:id/terms/:taxonomy
Content-Type: application/json

{
  "termIds": ["term_news", "term_featured"]
}

Endpoint delle aree widget

Elencare aree widget

GET /_emdash/api/widget-areas

Ottenere un’area widget

GET /_emdash/api/widget-areas/:name

Creare un’area widget

POST /_emdash/api/widget-areas
Content-Type: application/json

{
  "name": "sidebar",
  "label": "Main Sidebar",
  "description": "Appears on posts"
}

Eliminare un’area widget

DELETE /_emdash/api/widget-areas/:name

Aggiungere un widget

POST /_emdash/api/widget-areas/:name/widgets
Content-Type: application/json

{
  "type": "content",
  "title": "About",
  "content": [...]
}

Aggiornare un widget

PUT /_emdash/api/widget-areas/:name/widgets/:id

Eliminare un widget

DELETE /_emdash/api/widget-areas/:name/widgets/:id

Riordinare i widget

POST /_emdash/api/widget-areas/:name/reorder
Content-Type: application/json

{
  "widgetIds": ["widget_1", "widget_2", "widget_3"]
}

Endpoint di gestione utenti

Elencare utenti

GET /_emdash/api/admin/users
GET /_emdash/api/admin/users?role=40
GET /_emdash/api/admin/users?search=john

Ottenere un utente

GET /_emdash/api/admin/users/:id

Aggiornare un utente

PATCH /_emdash/api/admin/users/:id
Content-Type: application/json

{
  "name": "John Doe",
  "role": 40
}

Abilitare un utente

POST /_emdash/api/admin/users/:id/enable

Disabilitare un utente

POST /_emdash/api/admin/users/:id/disable

Endpoint di autenticazione

Stato del setup

GET /_emdash/api/setup/status

Restituisce se il setup è completato e se esistono utenti.

Login con passkey

POST /_emdash/api/auth/passkey/options

Ottieni le opzioni di autenticazione WebAuthn.

POST /_emdash/api/auth/passkey/verify
Content-Type: application/json

{
  "id": "credential-id",
  "rawId": "...",
  "response": {...},
  "type": "public-key"
}

Verifica la passkey e crea la sessione.

POST /_emdash/api/auth/magic-link/send
Content-Type: application/json

{
  "email": "[email protected]"
}
GET /_emdash/api/auth/magic-link/verify?token=xxx

Logout

POST /_emdash/api/auth/logout

Utente corrente

GET /_emdash/api/auth/me

Invitare un utente

POST /_emdash/api/auth/invite
Content-Type: application/json

{
  "email": "[email protected]",
  "role": 30
}

Gestione passkey

GET /_emdash/api/auth/passkey

Elenca le passkey dell’utente.

POST /_emdash/api/auth/passkey/register/options
POST /_emdash/api/auth/passkey/register/verify

Registra una nuova passkey.

PATCH /_emdash/api/auth/passkey/:id
Content-Type: application/json

{
  "name": "MacBook Pro"
}

Rinomina la passkey.

DELETE /_emdash/api/auth/passkey/:id

Elimina la passkey.

Endpoint di importazione

Analizzare esportazione WordPress

POST /_emdash/api/import/wordpress/analyze
Content-Type: multipart/form-data

file: <WXR file>

Eseguire importazione WordPress

POST /_emdash/api/import/wordpress/execute
Content-Type: application/json

{
  "analysisId": "...",
  "options": {
    "includeMedia": true,
    "includeTaxonomies": true,
    "includeMenus": true
  }
}

Limitazione delle richieste

Gli endpoint API possono essere soggetti a rate limiting in base alla configurazione del deployment. Quando si raggiunge il limite, le risposte includono:

HTTP/1.1 429 Too Many Requests
Retry-After: 60

CORS

L’API supporta CORS per le richieste dal browser. Configura le origini consentite nel tuo deployment.