SaaS CMS has officially launched! Learn more now.

David Buö
Nov 21, 2018
  7104
(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
A day in the life of an Optimizely Developer - London Meetup 2024

Hello and welcome to another instalment of A Day In The Life Of An Optimizely Developer. Last night (11th July 2024) I was excited to have attended...

Graham Carr | Jul 16, 2024

Creating Custom Actors for Optimizely Forms

Optimizely Forms is a powerful tool for creating web forms for various purposes such as registrations, job applications, surveys, etc. By default,...

Nahid | Jul 16, 2024

Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024