Try our conversational search powered by Generative AI!

Issues with Content Delivery API

Vote:
 

Hi,

 I followed the following page and installed the Episerver.ContentDeliveryApi package 2.11 on Episerver cms 11.15.0.  I am getting 404 when I try to access sitedefinition url or any other API content url. Here is what I did so far. I followed the instructions on this page https://world.episerver.com/documentation/developer-guides/content-delivery-api/getting-started/

1) I installed the following packages when installing EpiServer.ContentDeliveryApi package. I installed version 2.11 as that is version compatible with the Episerver cms version 11.15 that we have.

 <package id="EPiServer.ContentDeliveryApi" version="2.11.0" targetFramework="net471" />
  <package id="EPiServer.ContentDeliveryApi.Cms" version="2.11.0" targetFramework="net471" />
  <package id="EPiServer.ContentDeliveryApi.Core" version="2.11.0" targetFramework="net471" />
  <package id="EPiServer.ContentDeliveryApi.OAuth" version="2.6.0" targetFramework="net471" />

2) Set Access rights for the contentapiread Read access for root item and its descendants.

3) Created the following initialization class as shown 

[InitializableModule]
[ModuleDependency(typeof(ServiceContainerInitialization), typeof(ContentApiCmsInitialization))]
public class ContentApiInitialization : IConfigurableModule
{
	public void ConfigureContainer(ServiceConfigurationContext context)
	{
		context.Services.AddTransient<RoutingEventHandler, CustomContentApiRoutingEventHandler>();
		

		// set minimumRoles to empty to allow anonymous calls (for visitors to view site in view mode)
		context.Services.Configure<ContentApiConfiguration>(config =>
		{
			config.Default()
				.SetMinimumRoles(string.Empty)
				.SetSiteDefinitionApiEnabled(true);
		});
	}

        public void Initialize(InitializationEngine context)
        {
            
        }

        public void Uninitialize(InitializationEngine context)
        {
            
        }
}

4) It showed  CustomContentApiRoutingEventHandler is not found in the project. Hence searched and found this article and used this as the class as shown below:

https://world.episerver.com/forum/developer-forum/-Episerver-75-CMS/Thread-Container/2020/9/customcontentapiroutingeventhandler-namespace-not--found/

public class CustomContentApiRoutingEventHandler : RoutingEventHandler
    {
        public CustomContentApiRoutingEventHandler(
            IContentRouteEvents routeEvents,
            ServiceAccessor<HttpContextBase> httpContextAccessor,
            ContentApiRouteService contentApiRouteService)
            : base(routeEvents, httpContextAccessor, contentApiRouteService)
        {
        }

        // If language does not exists in the routing context, we return ContentLanguage.PreferredCulture as default language
        protected override string GetLanguage(SegmentContext routingContext, HttpRequestBase request)
        {
            var language = routingContext.Language ?? routingContext.ContentLanguage ?? ContentLanguage.PreferredCulture.Name;

            return language;
        }
    }

5) Then after compilation, tried to access the following urls

http://www.mywebsite.com/api/site/?language=en
http://www.mywebsite.com/api/episerver/v2.0/content/5/

But both of these returned 404. Am I missing something or made any mistake in trying to get the ContentDeliveryAPI? Could someone let me know How I can debug and see whats happening and how I can correct this issue with the ContentDeliveryApi.

Thanks in advance

#248759
Feb 17, 2021 2:25
Vote:
 

The accept-language is the primary way of setting the language you want else you'll get a 404. Can you try setting this header value to the language of the content you want when calling http://www.mywebsite.com/api/episerver/v2.0/content/5/

#248766
Feb 17, 2021 9:30
Vote:
 

I tried using postman to send the Accept-Language header, but it gave me 404 still when calling http://wwwmywebsite.com/api/episerver/v2.0/content/5/ 

#248788
Feb 17, 2021 17:20
Vote:
 

It may come from this setting in web.config:  episerver:contentdelivery:maphttpattributeroutes. If you don't install other apis, then, no need for this configuration (or its value should be true). This setting will decide whether .net engine should scan controllers and do routing or not. 

#263057
Sep 14, 2021 4:42
Vote:
 

Content suppliers, such as media businesses and e-commerce enterprises, pay CDN operators to transport their content to end-users. CDNs pay ISPs, carriers, and network operators to host servers in their data centers. The following are the two main mechanisms that explain how CDN works:

  • Maintain vital content in numerous, globally spread data centers so that it is closer to end consumers and hence quicker to download.
  • To provide the content OrientMCT to the user as quickly as possible, apply server optimizations based on content type.

Apart from improved performance, CDNs unload traffic provided straight from the content provider's origin infrastructure, potentially saving the content provider money. They're also good against DDoS attacks because they have their own network.

#270826
Jan 29, 2022 8:12
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.