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

When upgrading an existing project to Umbraco 12, you will need to opt-in explicitly for using the Delivery API. Below you will find the steps you need to take in order to configure it for your Umbraco project.

When you start with a fresh Umbraco 12 installation, the Delivery API is also disabled by default. To enable it, you can proceed directly to the Enable the Content Delivery API section, as the step below is already complete in this case.

Video tutorial

Register the Content Delivery API dependencies

  1. Open your project's Startup.cs file.

  2. Register the API dependencies in the ConfigureServices method by adding .AddDeliveryApi():

public void ConfigureServices(IServiceCollection services)
{
    services.AddUmbraco(_env, _config)
        .AddBackOffice()
        .AddWebsite()
        // Register all Delivery API dependencies
        .AddDeliveryApi()
        .AddComposers()
        .Build();
}

Enable the Content Delivery API

  1. Open your project's appsettings.json.

  2. Insert the DeliveryApi configuration section under Umbraco:CMS.

  3. Add the Enabled key and set its value to true:

appsettings.json
{
    "Umbraco": {
        "CMS": {
            "DeliveryApi": {
                "Enabled": true
            }
        }
    }
}

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.

appsettings.json
{
    "Umbraco": {
        "CMS": {
            "DeliveryApi": {
                "Enabled": true,
                "PublicAccess": true,
                "ApiKey": "my-api-key",
                "DisallowedContentTypeAliases": ["alias1", "alias2", "alias3"],
                "RichTextOutputAsJson": false
            }
        }
    }
}
  • 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.

Content item JSON structure

The Delivery API outputs the JSON structure outlined below to represent the retrieved content items, which consist of a range of properties:

  • Basic properties for any content item include name, createDate, updateDate, id and contentType.

  • All editorial properties from the content type can be found in the properties collection. Depending on the configured property editor, the property output value can be a string, number, boolean expression, array, object or null.

  • The route property provides the path of the content item, as well as details about the root node value that is represented by the startItem object. We will discuss the concept of a startItem in more detail in the next section.

  • If the content item varies by culture, the cultures property will contain information about all configured cultures for the content node, including the culture variant path and startItem for each one.

{
  "name": "string",
  "createDate": "2023-06-23T11:31:07.281Z",
  "updateDate": "2023-06-23T11:31:07.281Z",
  "route": {
    "path": "string",
    "startItem": {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "path": "string"
    }
  },
  "id": "11fb598b-5c51-4d1a-8f2e-0c7594361d15",
  "contentType": "string",
  "properties": {
    "property1Alias": "string",
    "property2Alias": 0,
    "property3Alias": true,
    "property4Alias": [],
    "property5Alias": {},
    "property6Alias": null
  },
  "cultures": {
    "cultureIsoCode1": {
      "path": "string",
      "startItem": {
        "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "path": "string"
      }
    },
    "cultureIsoCode2": {
      "path": "string",
      "startItem": {
        "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "path": "string"
      }
    }
  }
}
Start item

When working headlessly in a multi-site setup, sometimes it can be difficult to determine the site context of a particular content item. This is where the start item comes into play.

The start item represents the root of a content item and is commonly returned from the API in conjunction with a content path. For instance:

{
  "route": {
    "path": "/articles/2023/getting-started",
    "startItem": {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "path": "docs-portal"
    }
  }
}

This means that the content item resides under the docs-portal root node and can be retrieved using the path /articles/2023/getting-started.

The start item can also be helpful through the Start-Item request header when obtaining content from the Delivery API. Supplying a root node id or path as the header value, allows you to specify which is the starting point for the requested content operation:

GET /umbraco/delivery/api/v1/content/item/articles/2023/getting-started
Start-Item: docs-portal
Output expansion

Output expansion allows you to retrieve additional data about related content or media in the API output for a given content item.

By default, a content property that allows picking a different content item (like a content picker property) outputs a shallow representation of the item. That means, only the basic information about the picked item, without the item properties. However, with output expansion, it is possible to include the properties of the picked item in the API output. Similar shallow representation applies to media items, as well.

Currently, output expansion allows you to retrieve one level of property data from the point of view of the requested content node. This means that you can expand the properties of the chosen content item, but not the properties of other related items within that item.

This feature can be used when querying for both single and multiple content items by adding an expand parameter to the query. The value of this parameter can be either "all" to expand all properties of the requested content item or "property:alias, alias, alias" to expand specific ones.

The following JSON snippet demonstrates the default output of a content item (without expanding any properties).

Request

GET /umbraco/delivery/api/v1/content/item/9bdac0e9-66d8-4bfd-bba1-e954ed9c780d

Response

Shallow output for
{
    "name": "My post",
    "createDate": "2023-05-11T00:05:31.878211",
    "updateDate": "2023-05-15T11:25:53.912058",
    "route": {...
    },
    "id": "9bdac0e9-66d8-4bfd-bba1-e954ed9c780d",
    "contentType": "blogpost1",
    "properties": {
        "title": "My post page",
        "blogPostNumber": 11,
        "bodyContent": "Congue, sollicitudin? Est fames maiores, sociis suspendisse et aliquet tristique excepturi, aliquam, nihil illum pretium penatibus exercitationem lacinia! Dolorem tempus convallis, nulla! Eius scelerisque voluptatum penatibus, dignissimos molestiae, soluta eum. Voluptatibus quod? Temporibus potenti voluptates dictumst? Cillum metus, nec asperiores? Impedit sit! Eum tellus cillum facilisis ullamco tempor? Sint nostrum luctus? Neque dictumst diam, minus? Itaque, minus, etiam dignissimos debitis occaecat aptent tempus! Praesent molestiae duis nihil recusandae, eius imperdiet aspernatur natus. Tempus mattis at architecto, augue, consequuntur ultricies eligendi, litora morbi ante nesciunt pretium laoreet quidem recusandae voluptates dapibus, iure sagittis donec ipsum mollit? Blanditiis! Laborum sit assumenda beatae.",
        "linkedItem": {
            "name": "Demo blog",
            "createDate": "2023-05-11T00:26:52.591927",
            "updateDate": "2023-05-16T12:43:41.339963",
            "route": {
                "path": "/demo-blog/",
                "startItem": {
                    "id": "5d5ae914-9885-4ee0-a14b-0ab57f501a55",
                    "path": "demo-blog"
                }
            },
            "id": "5d5ae914-9885-4ee0-a14b-0ab57f501a55",
            "contentType": "blog",
            "properties": {}
        }
    },
    "cultures": {}
}

Below is an example of how an expanded representation might look for the linkedItem property that references another content item with properties title and description:

Request

GET /umbraco/delivery/api/v1/content/item/9bdac0e9-66d8-4bfd-bba1-e954ed9c780d?expand=property:linkedItem

Response

Expanded output for
{
    "name": "My post",
    "createDate": "2023-05-11T00:05:31.878211",
    "updateDate": "2023-05-15T11:25:53.912058",
    "route": {
        "path": "/my-post/",
        "startItem": {
            "id": "5d5ae914-9885-4ee0-a14b-0ab57f501a55",
            "path": "demo-blog"
        }
    },
    "id": "9bdac0e9-66d8-4bfd-bba1-e954ed9c780d",
    "contentType": "blogpost1",
    "properties": {
        "title": "My post page",
        "blogPostNumber": 11,
        "bodyContent": "Congue, sollicitudin? Est fames maiores, sociis suspendisse et aliquet tristique excepturi, aliquam, nihil illum pretium penatibus exercitationem lacinia! Dolorem tempus convallis, nulla! Eius scelerisque voluptatum penatibus, dignissimos molestiae, soluta eum. Voluptatibus quod? Temporibus potenti voluptates dictumst? Cillum metus, nec asperiores? Impedit sit! Eum tellus cillum facilisis ullamco tempor? Sint nostrum luctus? Neque dictumst diam, minus? Itaque, minus, etiam dignissimos debitis occaecat aptent tempus! Praesent molestiae duis nihil recusandae, eius imperdiet aspernatur natus. Tempus mattis at architecto, augue, consequuntur ultricies eligendi, litora morbi ante nesciunt pretium laoreet quidem recusandae voluptates dapibus, iure sagittis donec ipsum mollit? Blanditiis! Laborum sit assumenda beatae.",
        "linkedItem": {
            "name": "Demo blog",
            "createDate": "2023-05-11T00:26:52.591927",
            "updateDate": "2023-05-16T12:43:41.339963",
            "route": {
                "path": "/demo-blog/",
                "startItem": {
                    "id": "5d5ae914-9885-4ee0-a14b-0ab57f501a55",
                    "path": "demo-blog"
                }
            },
            "id": "5d5ae914-9885-4ee0-a14b-0ab57f501a55",
            "contentType": "blog",
            "properties": {
                "title": "My demo blog",
                "description": "Nihil incididunt dolores adipisicing placeat quisque imperdiet interdum autem, dolorem fusce rhoncus sunt leo inventore dictumst quisque, voluptatem, magni justo nostrud deserunt! Natus ipsam commodi dignissimos, sodales ab.\n"
            }
        }
    },
    "cultures": {}
}

The built-in property editors in Umbraco that allow for output expansion are:

  • Umbraco.ContentPicker

  • Umbraco.MediaPicker

  • Umbraco.MediaPicker3

  • Umbraco.MultiNodeTreePicker

Preview

Similar to the preview concept in Umbraco, the Delivery API allows for requesting unpublished content through its endpoints. This can be done by setting a Preview header to true in the API request. However, accessing draft versions of your content nodes requires authorization via an API key configured in appsettings.json file - Umbraco:CMS:DeliveryApi:ApiKey setting. To obtain preview data, you must add the Api-Key request header containing the configured API key to the appropriate endpoints, like:

GET /umbraco/delivery/api/v1/content/item/11fb598b-5c51-4d1a-8f2e-0c7594361d15
Preview: true
Api-Key: my-api-key

Draft content is not going to be included in the JSON response otherwise.

Localization

If your content is available in multiple languages, the Delivery API can resolve localized content. When querying content by id, the Accept-Language header can be used to request variant content.

GET /umbraco/delivery/api/v1/content/item/11fb598b-5c51-4d1a-8f2e-0c7594361d15
Accept-Language: en-US

When querying content by path, the culture is already known and included in the path, making the Accept-Language header unnecessary. However, if the header is present in the request, its value will take precedence over any other configuration settings. Localization is also supported by the means of the CMS's culture and hostname configuration.

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) and not its integer node id.

Gets a content item by id

GET /umbraco/delivery/api/v1/content/item/{id}

Returns a single item.

Path Parameters

NameTypeDescription

id*

String

GUID of the content item

Query Parameters

NameTypeDescription

expand

String

Which properties to expand and therefore include in the output if they refer to another piece of content

Headers

NameTypeDescription

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/v1/content/item/{path}

Returns a single item.

Path Parameters

NameTypeDescription

path*

String

Path of the content item

Query Parameters

NameTypeDescription

expand

String

Which properties to expand and therefore include in the output if they refer to another piece of content

Headers

NameTypeDescription

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/v1/content/item

Returns single or multiple items by id.

Query Parameters

NameTypeDescription

id*

String Array

GUIDs of the content items

expand

String

Which properties to expand in the response

Headers

NameTypeDescription

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/v1/content

Returns single or multiple items.

Query Parameters

NameTypeDescription

fetch

String

Structural query string option (e.g. ancestors, children, descendants)

filter

String Array

Filtering query string options (e.g. contentType, name)

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

Headers

NameTypeDescription

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, 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 Output expansion concept for more information about the benefits of this parameter.

?expand=all All expandable properties on the retrieved content item will be expanded.

?expand=property:alias1 A specific expandable property with the property alias alias1 will be expanded.

?expand=property:alias1,alias2,alias3 Multiple expandable properties with the specified property aliases will be expanded.

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 Startup.cs:

Startup.cs
using Umbraco.Cms.Api.Common.DependencyInjection;
using Umbraco.Cms.Core;

Now we can add the following code snippet to the ConfigureServices() method in Startup.cs:

Startup.cs
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers().AddJsonOptions(
        Constants.JsonOptionsNames.DeliveryApi,
        options =>
        {
            // set the maximum allowed depth of
            options.JsonSerializerOptions.MaxDepth = {desired max depth}
        });
    ...

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

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