Try our conversational search powered by Generative AI!

David Buö
Nov 21, 2018
  7091
(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
Product Listing Page - using Graph

Optimizely Graph makes it possible to query your data in an advanced way, by using GraphQL. Querying data, using facets and search phrases, is very...

Jonas Bergqvist | Jul 5, 2024

Optimizely Search and Navigation - Part 2 - Filter Tips

Introduction Continuing from Part 1 – Search Tips , today I will share the next part – filter tips. The platform versions used for this article are...

Binh Nguyen Thi | Jul 1, 2024

Integrating HubSpot CRM without the MA Connector

Have HubSpot CRM? Want to push user data into it from Optimizely? Don’t have any personalisation requirements with that data? Don’t want to pay $80...

Matt Pallatt | Jun 27, 2024

Keeping the website secure by updating external packages

Did you see the latest warning from Optimizely to update this package with a critical security warning? https://world.optimizely.com/documentation/...

Daniel Ovaska | Jun 27, 2024