I am working on SXC 9.2 and writing custom plugin. I need to pick Category information so I have written the below code to get the category information.

public class CustomCategoryCommand : CommerceCommand
        private GetCategoryCommand _getCategoryCommand;

        public async Task<Category> Process(CommerceContext commerceContext, string categoryID)
            //Category category = null;

            Category category = await this._getCategoryCommand.Process(commerceContext, categoryID);

            return category;

        public CustomCategoryCommand(
                GetCategoryCommand getCategoryCommand
            this._getCategoryCommand = getCategoryCommand;

It is always returning null. While debugging I could not find any exception. It is simply returning null.

Parameter- CategoryId: Entity-Category-Habitat_Master-Departments (Existing habitat categoryId)

Please, can somebody indicate what mistake am I doing here !!!!


  • Please add to your question - ApiController that you have created for this command, how you registered OData API method, how you have defined component and snippet from ConfigureSitecore.cs so we can see how this command is wired up with other elements Commented Nov 27, 2019 at 6:00
  • Thanks Peter for your input. Yes I have registered. I am able to debug as well. Code execution pointer reach to the above mentioned code.
    – Jitendra
    Commented Nov 27, 2019 at 6:23
  • Could you provide commerceContext.Headers keys and values? Looks like you are passing a wrong Environment header value or it's missing in your request. Should be Environment: HabitatAuthoring Commented Nov 27, 2019 at 11:34
  • HeaderKeys: Content-Type=application/json; Authorization={{SitecoreIdToken}} Using BabitatAuthoring environment only. Thanks.
    – Jitendra
    Commented Nov 27, 2019 at 14:57

1 Answer 1


It usually happens when you call your custom api from postman and forget to add some required headers:


If Environment header was not passed to request, by default, XC resolves Environment as a Global Environment. In your case, you need to pass HabitatAuthoring environment.

Add them to your postman request headers and execute your request.

It should work now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.