Skip to content

Fragments API

The Fragments API provides endpoints for working with shared content fragments. Fragments are reusable content components (MDX or Puck) that can be referenced across multiple pages. Unlike pages, fragments are not site-scoped by default — they exist globally, though site-specific fragments can shadow global ones.

All endpoints are relative to the API base URL (default: /__cms/api).


List Fragments

GET /fragments

List all fragments with optional filters. When the site parameter is provided, returns a merged list of global and site-specific fragments with scope annotation (site fragments shadow global fragments with the same name).

Parameters:

NameInTypeRequiredDescription
collectionquerystringnoFilter by collection (default: all)
localequerystringnoFilter by locale
sitequerystringnoIf provided, return merged global + site-specific fragments (Dev Branch Preview)

Response: 200 OK

{
  items: ContentManifest[]
  total: number
}

Example:

# List all global fragments
curl http://localhost:4321/__cms/api/fragments

# List fragments for a specific collection
curl "http://localhost:4321/__cms/api/fragments?collection=components"

# List merged fragments for a site (site-specific + global)
curl "http://localhost:4321/__cms/api/fragments?site=default"

Check Fragment Name Availability

GET /fragments/name-available

Check whether a fragment name is available within a collection. Useful for validating names before creating or renaming fragments.

Parameters:

NameInTypeRequiredDescription
namequerystringyesFragment name to check
collectionquerystringnoCollection to check in (default: components)
localequerystringnoLocale to check in (default: en)
excludeIdquerystringnoExclude this content ID from the check (for rename operations)
sitequerystringnoCheck availability in site-specific scope (Dev Branch Preview)

Response: 200 OK

// Available
{
  available: true;
}

// Taken
{
  available: false;
  existingId: string; // ID of the fragment using this name
}

Errors:

StatusCodeDescription
400MISSING_REQUIRED_FIELDname query parameter not provided

Example:

curl "http://localhost:4321/__cms/api/fragments/name-available?name=hero-banner&collection=components"

Get Fragment by Name

GET /fragments/:name

Get a fragment by its name. When the site parameter is provided, looks up the site-specific fragment first, falling back to the global fragment.

Parameters:

NameInTypeRequiredDescription
namepathstringyesFragment name
collectionquerystringnoCollection to look in (default: components)
localequerystringnoIf provided, return only this locale’s data
sitequerystringnoSite-first lookup: check site fragments, then global (Dev Branch Preview)

Response: 200 OK

// ContentManifest (or filtered to single locale)
{
  id: string
  type: 'puck' | 'mdx'
  kind: 'fragment'
  collection: string
  locales: {
    [locale: string]: {
      locale: string
      etag: string
      created: string
      modified: string
      name: string
      meta: ContentMeta
    }
  }
}

Errors:

StatusCodeDescription
404CONTENT_NOT_FOUNDNo fragment with this name in the specified collection

Example:

# Get a fragment by name
curl "http://localhost:4321/__cms/api/fragments/hero-banner?collection=components"

# Get a fragment with site-first lookup
curl "http://localhost:4321/__cms/api/fragments/hero-banner?site=default"

# Get only the English locale
curl "http://localhost:4321/__cms/api/fragments/hero-banner?locale=en"