Optimizely Content Delivery API - getting started smoothly!

The Optimizely Content Delivery API adds headless capabilities to your traditional Optimizely Content Cloud CMS, making it a hybrid CMS. The best of both worlds, you might say.

The documentation is quite good, so I just want to mention the problems I had installing the Content Delivery API for the first time. And then, of course, how to solve those problems. If I had actually read the entire documentation, I would have found the solution to at least one of my problems... 😄

A route named 'MS_attributerouteWebApi' is already in the route collection

The first problem I faced after installing the Content Delivery API, was this message.

Server Error in '/' Application. A route named 'MS_attributerouteWebApi' is already in the route collection. Route names must be unique. Parameter name: name Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

After some investigation, I think the problem is multiple calls to MapHttpAttributeRoutes() and adding the following appsettings seems to fix the problem.

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

404 Content was not found from the API

The first thing I did after installing the Content Delivery API, and getting rid of the error message above, was try to test the API in my browser of choice, with the following result. I knew the content with id 8 existed, so I did not understand this response from the API.

NotFound - Content was not found

I made all kinds of changes to the configuration and even reached out to Optimizely support. I gave support access to my test site, and the answer I got was

It works on my machine!

Finally, a colleague of mine listened to my problems, did a quick Google search, and told me the solution within a minute! Thanks, Henning!

The problem was that the Accept-Language header must match the content you are querying for. The support guy obviously had different preferred language settings in his browser, so that's why it worked on his machine.

The easiest way of checking your browser settings is using a service like this. This is what my browser «accepts».

Your browser's Accept-Language header.

The easiest way to test the Content Delivery API is to use Postman, or a similar tool, where you have full control over the Accept-Language header.

After running some tests, my conclusion is that if presented with a list of languages (like from my browser) the Content Delivery API will only look at the first language and ignore the rest. Which, by the way, makes total sense!

Content Search API

While the documentation tells you how to use the Search API, I was unable to find the actual base URL! So, here it is:

/api/episerver/v2.0/search/content/

For details on how to use the API, refer to the documentation linked above.

Conclusion

Except for those three minor problems, getting started with the Content Delivery API was a piece of cake! 🍰