Umbraco Media Delivery API

Leverage Umbraco as your DAM

In this guide, we'll use Umbraco as a Digital Asset Management system and integrate it with Ucommerce. We'll use the Umbraco Media Delivery API to retrieve the information we need.

Here's a look at the final result:

A look at how Umbraco can be leveraged as a DAM system for Ucommerce

Prerequisites

Before you get started, please make sure both Umbraco templates and Ucommerce templates are installed.

Setup Projects

Umbraco

Create a new project using the Umbraco template. Make sure both delivery API and media is enabled in appsettings.json:

When Umbraco is installed, take it for a spin and add some images to the Media library:

Media added to Umbraco

Ucommerce

Create a new project using the Ucommerce Headless template.

Generate the Umbraco Client

To make Ucommerce communicate with Umbraco, we need a client to handle the REST calls to the Umbraco Delivery API. You can either code this yourself or use a tool to generate it. For this guide, we're going to use Microsoft Kiota to generate it for us.

First, install Microsoft Kiota as a .Net tool or as a VS Code extension.

Second, use Kiota to generate a client from the Umbraco Delivery API Specification using either the command line (see below) or the VS Code plugin UI.

The Umbraco Delivery API Specification can be found on https://localhost:{yourUmbracoPortNumber}/umbraco/swagger/delivery/swagger.json

See Optional parameters for more details on the command

Third, add the needed Kiota dependencies to the Ucommerce project.

Run kiota info --language CSharp to get a list of dependencies needed.

The csproj file should look similar to this:

Implementing UmbracoImageService.cs

In the Ucommerce project, create a new class UmbracoImageService that inherits from IImageService. This class is responsible for mapping between the UmbracoClient created previously and Ucommerce. See Images for more details.

Below is a complete example:

Each method is straightforward: Get the necessary data from Umbraco using the UmbracoClient, map the data to fit Ucommerce, and return the result.

Note that the ChildrenCount is set to null. This is because the Umbraco Delivery API does not contain any information on the number of children for a given node. See Media for more details on what that means.

Tying everything together

The last step needed is to set up UmbracoClient and UmbracoImageService in the Ucommerce project. Because the Umbraco Delivery API does not contain any information on the base URL, we'll have to set that up manually. As you might have noticed, we also need the base URL when mapping the URL as Umbraco returns only relative URLs.

UmbracoSettings.cs

The settings object is a single line of code:

UmbracoModuleExtensions.cs

To make the integration reusable, we suggest using an extension method for every module:

For the configuration to work, add the base URL to the following path in appsettings.json: Umbraco:BaseUrl:

The final step is to call AddUmbracoIntegration in Program.cs:

Congratulations! Ucommerce is now able to get images from Umbraco!

See it in action

Now, try taking the Ucommerce project for a spin and select an image for a product.

Last updated

Was this helpful?