Content Delivery Api works but Media Delivery Api returns 401

Hello,

I’m stuck in a situation where the Content Delivery Api works great (/umbraco/delivery/api/v2/content/item) but the Media Delivery Api (/umbraco/delivery/api/v2/media/item) does not. I receive 401 Unauthorized no matter what I attempt, and it’s clearly some kind of validation failure on the backend. Neither Umbraco Swagger, Postman nor Insomnia can get a success. I’ve checked configurations, order of services in Program.cs, appsettings.json configurations, Cors, etc. Everything appears to be configured correctly, Content Delivery Api is working superbly. No media. The reason I wanted to hit this API was because I figured it would get me custom properties from the media items (like Caption or Alt Text), etc.

Has anyone run into this and managed to solve it?

My current path forward is to create a custom API endpoint that provides the details that I need and that does seem to be working and needs to be further configured, but I feel like maybe I’m going in the wrong direction and could really use some guidance.

Thanks in advance.

Hi Chris

I’ve just tried to replicate this to see if it is a bug or not.

The good news is I got it working. If you would like to replicate my steps in a demo site then do the following:

  • Create a folder in your file system.
  • Open a command prompt in that location.
  • Install Umbraco using this script in the command prompt:
# Ensure we have the version specific Umbraco templates
dotnet new install Umbraco.Templates::16.2.0 --force

# Create solution/project
dotnet new sln --name "MySolution"
dotnet new umbraco --force -n "MyProject"  --friendly-name "Administrator" --email "[email protected]" --password "1234567890" --development-database-type SQLite
dotnet sln add "MyProject"


#Add starter kit
dotnet add "MyProject" package clean

dotnet run --project "MyProject"
#Running
  • Then in Program.cs add .AddDeliveryApi() to builder.CreateUmbracoBuilder()
  • Then in the app settings add this section inside Umbraco > CMS just after Security
      "DeliveryApi": {
        "Enabled": true,
        "PublicAccess": false,
        "ApiKey": "my-api-key",
        "Media": {
          "Enabled": true,
          "PublicAccess": false
        }
      } 

With all of that in place you should be able to do GET request in Postman. Just make sure the localhost port number is correct to your local project.

Url: https://localhost:44367/umbraco/delivery/api/v2/media/item/3c6c415c-35a0-4629-891e-683506250c31

Headers
Api-Key: “my-api-key”

Let me know how you get on

Kind regards

Paul Seal

Hey Paul, thank you very much. My apologies for the late response, I have been ill.

I ran through Clean and was able to see that it works, I’ll have to restructure my project to see if I can base it off of Clean Headless. I have already done so much to get things where they are and I’m worried about losing progress on it. I think this points me in the right direction though, thank you for the help. - Cheers

Just to make sure:

You need to enable the media API seperately as described in @prjseal example config.

The Media configuration can only be more restrictive! This is a very important caveat. This is what the docs say about it:

The Media configuration can only become more restrictive than the DeliveryApi configuration:

  • If DeliveryApi:Enabled is false, the DeliveryApi:Media:Enabled configuration option has no effect. The Media Delivery API cannot be enabled on its own.

  • If DeliveryApi:PublicAccess is false, the DeliveryApi:Media:PublicAccess configuration option has no effect. The Media Delivery API cannot be publicly available if the Content Delivery API is not.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.