Content Delivery API
Get started with the Content Delivery API.
The Content Delivery API delivers headless capabilities built directly into Umbraco. It allows you to retrieve your content items in a JSON format and lets you preset them in different channels, using your preferred technology stack. This feature preserves the friendly editing experience of Umbraco, while also ensuring a performant delivery of content in a headless fashion. And with its different extension points, you can tailor this API to fit a broad range of requirements.
Getting Started
The Delivery API is an opt-in feature of Umbraco. It must be explicitly enabled through configuration before it can be utilized.
Enable the Content Delivery API
Open your project's
appsettings.json
.Insert the
DeliveryApi
configuration section underUmbraco:CMS
.Add the
Enabled
key and set its value totrue
:
Once the Content Delivery API is enabled, you will need to manually rebuild the Delivery API content index (DeliveryApiContentIndex). This can be done using the "Examine Management" dashboard in the "Settings" section. Once the index is rebuilt, the API will be able to serve the latest content from the multiple-items endpoint.
Additional configuration
When the Delivery API is enabled in your project, all your published content will be made available to the public by default. However, a few additional configuration options will allow you to restrict access to the Delivery API endpoints and limit the content that is returned.
Umbraco:CMS:DeliveryApi:PublicAccess
determines whether the Delivery API (if enabled) should be publicly accessible or if access should require an API key.Umbraco:CMS:DeliveryApi:ApiKey
specifies the API key to use for authorizing access to the API when public access is disabled. This setting is also used for accessing draft content for preview.
Are you using Umbraco Cloud?
When hosting your Umbraco website on Umbraco Cloud, security should always be prioritized for sensitive information like API keys. Rather than storing it as plain text in the appsettings.json
file, it is strongly encouraged to use Umbraco Cloud's built-in secrets management. This feature allows you to securely store and manage sensitive data, keeping your API key safe from potential exposure or unauthorized access. To learn more about implementing Secrets management, read the Secrets management documentation.
Umbraco:CMS:DeliveryApi:DisallowedContentTypeAliases
contains the aliases of the content types that should never be exposed through the Delivery API, regardless of any other configurations.
Another valuable configuration option to consider when working with the Delivery API is RichTextOutputAsJson
:
Umbraco:CMS:DeliveryApi:RichTextOutputAsJson
enables outputting rich text content as JSON rather than the default HTML output. JSON can be a preferred format in many scenarios, not least because it supports the routing of internal links better than HTML does.
To test the functionality of the API, you need to create some content first.
Concepts
Before exploring the API endpoints detailed below, there are a few concepts to keep in mind.
Endpoints
The output produced by the Delivery API can either represent a specific content item or a paged list of multiple items.
When referring to a specific content item in your API requests, the id
parameter always refers to the item’s key (GUID). It does not refer to its integer node id.
Gets a content item by id
GET
/umbraco/delivery/api/v2/content/item/{id}
Returns a single item.
Path Parameters
id*
String
GUID of the content item
Query Parameters
expand
String
Which properties to expand and therefore include in the output if they refer to another piece of content
fields
String
Which properties to include in the response (by default all properties are included)
Headers
Accept-Language
String
Requested culture
Api-Key
String
Access token
Preview
Boolean
Whether draft content is requested
Start-Item
String
URL segment or GUID of the root content item
Gets a content item by route
GET
/umbraco/delivery/api/v2/content/item/{path}
Returns a single item.
Path Parameters
path*
String
Path of the content item
Query Parameters
expand
String
Which properties to expand and therefore include in the output if they refer to another piece of content
fields
String
Which properties to include in the response (by default all properties are included)
Headers
Accept-Language
String
Requested culture
Api-Key
String
Access token
Preview
Boolean
Whether draft content is requested
Start-Item
String
URL segment or GUID of the root content item
Gets content item(s) by id
GET
/umbraco/delivery/api/v2/content/items
Returns single or multiple items by id.
Query Parameters
id*
String Array
GUIDs of the content items
expand
String
Which properties to expand in the response
fields
String
Which properties to include in the response (by default all properties are included)
Headers
Accept-Language
String
Requested culture
Api-Key
String
Access token
Preview
Boolean
Whether draft content is requested
Start-Item
String
URL segment or GUID of the root content item
Gets content item(s) from a query
GET
/umbraco/delivery/api/v2/content
Returns single or multiple items.
Query Parameters
fetch
String
Structural query string option (e.g. ancestors
, children
, descendants
)
filter
String Array
Filtering query string options (e.g. contentType
, name
, createDate
, updateDate
)
sort
String Array
Sorting query string options (e.g. createDate
, level
, name
, sortOrder
, updateDate
)
skip
Integer
Amount of items to skip
take
Integer
Amount of items to take
expand
String
Which properties to expand and therefore include in the output if they refer to another piece of content
fields
String
Which properties to include in the response (by default all properties are included)
Headers
Accept-Language
String
Requested culture
Api-Key
String
Access token
Preview
Boolean
Whether draft content is requested
Start-Item
String
URL segment or GUID of the root content item
All endpoints are documented in a Swagger document at {yourdomain}/umbraco/swagger
. Keep in mind that this document is not available in production mode by default. For more information check the API versioning and OpenAPI article.
Query parameters
The Content Delivery API provides a number of query parameters that allow you to customize the content returned by the API to fit your needs. For each endpoint, the relevant query parameters are already specified within their corresponding documentation above. In addition to standard parameters like skip
and take
, the API provides different possibilities for the value of expand
, fields
, fetch
, filter
and sort
parameters. Below are the options supported out of the box.
You can extend the built-in selector, filter, and sorting capabilities of the Delivery API by creating your own custom query handlers.
Refer to the Property expansion and limiting concept for more information about this parameter.
?expand=properties[$all]
All expandable properties on the retrieved content item will be expanded.
?expand=properties[alias1]
A specific expandable property with the property alias alias1
will be expanded.
?expand=properties[alias1,alias2,alias3]
Multiple expandable properties with the specified property aliases will be expanded.
?expand=properties[alias1[properties[nestedAlias1,nestedAlias2]]]
The property with the property alias alias1
will be expanded, and likewise the properties nestedAlias1
and nestedAlias2
of the expanded alias1
property.
Extension points
The Delivery API has been designed with extensibility in mind, offering multiple extension points that provide greater flexibility and customization options. These extension points allow you to tailor the API's behaviour and expand its capabilities to meet your specific requirements.
You'll find detailed information about the specific areas of extension in the articles below:
Handling deeply nested JSON output
.NET imposes a limit on the depth of object nesting within rendered JSON. This is done in an effort to detect cyclic references. Learn more about it in the official .NET API docs.
If the limit is exceeded, .NET will throw a JsonException
.
In some cases the content models might be so deeply nested that the Delivery API produces JSON that exceeds this limit. If this happens, the JsonException
will be logged and shown in the Umbraco log viewer.
To handle this we have to change the limit. Since the Delivery API has its own JSON configuration, we can do so without affecting the rest of our site.
First, we have to add these using
statements to Program.cs
:
Now we can add the following code snippet to the Program.cs
file:
Current Limitations
The Content Delivery API provides a powerful and flexible way to retrieve content from the Umbraco CMS. There are, however, certain limitations to be aware of.
In this section, we will discuss some of the known limitations of the API, and how to work around them if necessary.
Protected content
The Delivery API supports protected content and member authentication. This is however an opt-in feature. You can read more about it in the Protected Content in the Delivery API article.
If member authentication is not explicitly enabled, protected content is ignored and never exposed by the Delivery API.
As a result, lifting protection from a content item requires an additional step to ensure it becomes accessible through the Delivery API. The recommended way is to publish the content item again. Alternatively, you can manually rebuild the DeliveryApiContentIndex to reflect the changes.
Property editors
There are certain limitations associated with some of the built-in property editors in Umbraco. Let's go through these below:
Grid Layout (legacy)
The Legacy Grid in Umbraco is supported to a certain extent. However, keep in mind that it may not be suitable for headless content scenarios. Instead, we recommend using the Block Grid property editor.
Rich Text Editor
The Delivery API is not going to support the rendering of Macros within the Rich Text Editor. Therefore, any Macros included in the content will not be executed or output when retrieving content through the API.
When outputting the Rich Text Editor content as HTML (the default format), be aware that internal links may be insufficient in a multi-site setup. There is a possibility that this limitation may be addressed in future updates. However, consider the alternative approach to rendering the Rich Text Editor content as JSON.
Member Picker
The Member Picker property editor is not supported in the Delivery API to avoid the risk of leaking member data.
Multinode Treepicker
The Multinode Treepicker property editor, when configured for members, is also unsupported in the Delivery API. This is due to the same concern of potentially leaking member data.
Making changes to DisallowedContentTypeAliases
DisallowedContentTypeAliases
When changing the content type aliases in the Umbraco:CMS:DeliveryApi:DisallowedContentTypeAliases
configuration setting, the DeliveryApiContentIndex should be rebuilt. This ensures that the disallowed content types are not exposed through the Delivery API.
Alternatively the relevant content items can be republished. This will ensure that the changes are reflected, eliminating the need to rebuild the index.
Last updated