image

Lesson learned while working with Episerver Commerce Service API

image By - Ravindra Rathore
15 Dec 2020
 

Hi Guys,

Recently I got a chance to work with Episerver Commerce Service API to import the Catalogs and Products from XML to the Commerce manager.

Episerver provided very detailed documentation for the APIs so you will not face issues while working with these APIs.

Still, I am sharing some issues while configuring the Episerver Commerce Service API and while importing the data to the Commerce manager.

Installation/Configuration related issues-

Episerver provided very detailed documentation related to installation. You can find it here

  1. Token route (/episerverapi/token) returns 404 - You may face one issue related to OWIN startup and because of this your Token route (/episerverapi/token) returns 404. Its a common issue that lots of developers while working with service APIs.
    Fix – While Configuring OWIN startup class make sure you put initial it with

     [assembly: OwinStartup(typeof(Test.Web.Startup))]

    Example
    using EPiServer.ServiceApi.Owin;
    using Microsoft.Owin;
    using Owin;
                  
    [assembly: OwinStartup(typeof(Test.Web.Startup))]
    namespace Test.Web
    {
            public class Startup
            {
                public void Configuration(IAppBuilder app)
                {
                    // Enable bearer token authentication using Membership for Service Api
                    app.UseServiceApiMembershipTokenAuthorization();
                }
            }
    }

    OR Add the below lines in web.config inside app setting
    <add key="owin:AppStartup" value="Web.Startup, Web" />
    <add key="owin:AutomaticAppStartup" value="true" />

FYI – After adding this class or settings in web.config make you reset your IIS or try running your solution in debug mode(Press F5) because sometimes your site did not detect these changes and you will still face the same issue.

You may face some common issues and Māris already written a great article here on it.

Service API Issues

  1. Update Service API issue – As you all know Episerver exposed a list of endpoints for performing the CRUD operations (here) but while using one of its service API endpoints I noticed that it overwrites the data instead of update.
    Ex- Like you have a product or node that has Metadata values in multiple languages (en-US, en-CA, etc..) and data is coming from multiple files so in first call it will create the node but when you fetch the node of en-US and try to update it with en-CA language values it creates a new item and put the en-CA language values only.

    Fix -

    1. Best way to merge all the XML files into one file and merge language node/products in a single node using the custom code and manually and then perform the create operation.
    2. If you can’t merge the files since it has lots of data or because of any other reason than the other way is while performing the create/update operation from XML files fetch the existing item and its Metadata using GET service API and perform the merge here and then send the final object with create/update call.

Thanks for reading this blog post I hope it helps

Thanks and regards

Ravindra S. Rathore