Sitecore Commerce Journal – ODataUnrecognizedPathException: Resource not found for the segment

The structure for creating a sitecore commerce plugin is well defined and lot of samples and help is available online but when you start with actual implementation based on needs thing change a little.
While working on creating an import plugin for Sitecore Commerce which will populate catalog, categories and products data into sitecore commerce, I encountered an error stating,

<h2 class="stackerror">ODataUnrecognizedPathException: Resource not found for the segment ' ImportSellableItemsCommand'.</h2>
<ul>
<li class="frame" id="frame1">
<h3>Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.CreateFirstSegment(string segmentText)</h3>
</li>
<li class="frame" id="frame2">
<h3>Microsoft.OData.Core.UriParser.Parsers.ODataPathParser.ParsePath(ICollection<string> segments)</h3>
</li>
<li class="frame" id="frame3">
<h3>Microsoft.OData.Core.UriParser.Parsers.ODataPathFactory.BindPath(ICollection<string> segments,

At first glance it looked to be a OData reference problem which apparently was not as I updated OData reference to correct versions into the plugin and commerce engine project yet was seeing the same error.
Second thought was to specify or decorate the ActionResult method in controller with a Route attribute, this too didn’t solve the problem.

In my case I was not specifying a correct controller name in ConfigureServiceApiBlock.cs. This is how I wrote it, which was incorrect.

I specified the commands name thinking it is expecting a CommerceCommand as the next line was expecting a CommerceCommand

The correct way is to have ActionResult Method Name from the Controller.

Correct code snippet is

The same error will also appear if .ConfigurePipeline<IConfigureServiceApiPipeline>(configure => configure.Add<ConfigureServiceApiBlock>()) is not added after aAddPipeline line is added in ConfigureSitecore.cs.

Correct code snippet is

Below error appears when ActionResult Method name is not matching in the controller as compared to being called from postman

<div class="titleerror">NotSupportedException: No action match template 'Commands/ImportSellableItems' in 'CommandsController'</div>
        <p class="location">Microsoft.AspNetCore.OData.Routing.Conventions.DefaultODataRoutingConvention.SelectAction(RouteContext routeContext)</p> 

In our case it was a typo, but the point here is to have correct method name and that too must be the same in the postman call.

All above errors are not due to Sitecore Commerce as a platform but human errors which you do while working and learning a new technology. Learning from errors is fruitful isn’t it?

Leave a Reply

Your email address will not be published. Required fields are marked *