Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

David Buö
Nov 21, 2018
  7007
(5 votes)

Get started with Content Delivery API 2.2.0

I just installed the latest version of Episerver Content Delivery API 2.2.0 and  just wanted to share some quick findings in order for you guys to get it up and running quickly.

I started by installing the following packages in visual studio, Episerver.ContentDeliveryApi.Search is optional and requires Episerver Find. Installation on to the latest Alloy went smooth and without dependency/build errors.

 

When I tried to run the site I got the following error regarding MS_attributerouteWebApi

I went to the documentation and under the configuration section for the content delivery api documentation (link) I found my answer. By installing both the CMS and the Search package I’m calling (HttpConfiguration)config.MapHttpAttributeRoutes() two times. In order to fix this error, I followed the instructions in the documentation and disabled settings from ContentDeliveryApiSearch by adding the following to my <appSettings>

<add key="episerver:contentdeliverysearch:maphttpattributeroutes" value="false" />

Note: You may be needed to disable settings for the cms package as well if you're already running the ServiceAPI (its explained in the link above).

With the change the site ran smoothly, and I could make sure that the contentapiread user had the proper access and start querying in the browser (e.g. http://localhost:61704/api/episerver/v2.0/site/)

 

Although when moving over to Postman I only got back a response in HTML which included the log-in screen. I realized it had something to do with authorization. Since I just wanted to get started quickly I looked at our music festival demo site (link) where they set the default minimum role to Empty in order to bypass the step of authorization. This suits me quite well when exploring the API in localhost so I created an Initialization module that sets the default minimum role to Empty.

    [ModuleDependency(typeof(ContentApiCmsInitialization))]
    public class ContentDeliveryApiInitialization : IConfigurableModule
    {
        public void Initialize(InitializationEngine context)
        {
            //Add initialization logic, this method is called once after CMS has been initialized
        }

        public void Uninitialize(InitializationEngine context)
        {
            //Add uninitialization logic
        }


        public void ConfigureContainer(ServiceConfigurationContext context)
        {
            // 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);
            });
        }
    }

 After a rebuild everything was set up and the querying from Postman worked as well.

 

Hopefully this helps you to get the API up and running and start exploring its capabilities.

Nov 21, 2018

Comments

valdis
valdis Nov 23, 2018 06:53 AM

I would recommend to rethink whole attribute based mapping initialization routine and "promote" call to some generic module. meaning that there might be multiple packages installed that require attribute based routing, those register some hooks that episerver initialization engine can callback and initialize every single package. that would avoid cases like these. very similar as IConfigurableModule and friends are working - somebody (frameowrk) is calling me. hollywood effect.

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog