Try our conversational search powered by Generative AI!

David Buö
Nov 21, 2018
  7016
(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
Why C# Developers Should Embrace Node.js

Explore why C# developers should embrace Node.js especially with Optimizely's SaaS CMS on the horizon. Understand the shift towards agile web...

Andy Blyth | May 2, 2024 | Syndicated blog

Is Optimizely CMS PaaS the Preferred Choice?

As always, it depends. With it's comprehensive and proven support for complex business needs across various deployment scenarios, it fits very well...

Andy Blyth | May 2, 2024 | Syndicated blog

Adding market segment for Customized Commerce 14

Since v.14 of commerce, the old solution  for adding market segment to the url is not working anymore due to techinal changes of .NET Core. There i...

Oskar Zetterberg | May 2, 2024

Blazor components in Optimizely CMS admin/edit interface

Lab: Integrating Blazor Components into Various Aspects of Optimizely CMS admin/edit interface

Ove Lartelius | May 2, 2024 | Syndicated blog

Anonymous Tracking Across Devices with Optimizely ODP

An article by Lead Integration Developer, Daniel Copping In this article, I’ll describe how you can use the Optimizely Data Platform (ODP) to...

Daniel Copping | Apr 30, 2024 | Syndicated blog

Optimizely Forms - How to add extra data automatically into submission

Some words about Optimizely Forms Optimizely Forms is a built-in add-on by Optimizely development team that enables to create forms dynamically via...

Binh Nguyen Thi | Apr 29, 2024