2

I'm using Sitecore 9 and I have created a ServiceApiController to enhance Sitecore API.

I put a simple action method but it doesn't catch any request and I get this exception:

Document not found - 404

Here is my controller:

using Sitecore.Services.Core;
using Sitecore.Services.Infrastructure.Web.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;

namespace SPCW.Feature.SalesforceBridge.Controllers
{
    public class TestApi : ServicesApiController
    {
        [System.Web.Http.HttpGet]
        [System.Web.Http.Route("v1/test")]
        public IHttpActionResult testMethod()
        {
            return Ok<string>("Test was successful");
        }
    }
}

and here is my configuration

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <api>
      <services>
        <configuration type="Sitecore.Services.Infrastructure.Configuration.ServicesConfiguration, Sitecore.Services.Infrastructure">
          <allowedControllers hint="list:AddController">
            <allowedController desc="TestApi">SPCW.Feature.SalesforceBridge.Controllers.TestApi, SPCW.Feature.SalesforceBridge</allowedController>
          </allowedControllers>
        </configuration>
      </services>
    </api>
  </sitecore>
</configuration>
2

First, you need to add "Controller" at the end of your controller class name so instead of TestApi it will be TestApiController to follow MVC naming conventions.

Second, I think that better would be to decorate your class with this attribute [ServicesController("v1.test")] .

Then the call would look like this: http://localhost/sitecore/api/ssc/v1/test/1/TestMethod

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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