Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • manila 217 posts 479 karma points
    Aug 10, 2018 @ 11:07

    I am unable to hit Get method in WebAP

    I have WebAPI2 project in my solution where I;m using umbraco 7 as a startup project.

    I have trouble to hit webapi action. I am getting 500 error in the console and the api is not reached.

    This is my ajax call:

    function getProducts() {
        var response;
            .done(function (data) {
                response = $.map(data,
                    function (item) {
                        return { label: item.Name + ' (' + item.Code + ')' };
        return response;

    The ajax is not hitting. The request skips getJson call and returns undefined response.

    This is my api controller method:

    public class ProductController : ApiController {
    // GET api/<controller>
        public IEnumerable<ProductModel> ProductList()
            ProductSearcher searcher = new ProductSearcher();
            return searcher.GetResults();

    In the config I have defined:

            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }

    Postman returns Object reference not set to an instance of an object but it doesn't even hit the ProductList either.

    I have selected to run multiple projects - my app start project and web api project.

    This is the error stacktrace - it looks to me like umbraco does looks for routing while I need to route to non-umbraco api:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Umbraco.Web.Routing.ContentLastChanceFinderByNotFoundHandlers.HandlePageNotFound(PublishedContentRequest docRequest) +152
       Umbraco.Web.Routing.ContentLastChanceFinderByNotFoundHandlers.TryFindContent(PublishedContentRequest docRequest) +10
       Umbraco.Web.Routing.PublishedContentRequestEngine.HandlePublishedContent() +529
       Umbraco.Web.Routing.PublishedContentRequestEngine.FindPublishedContentAndTemplate() +250
       Umbraco.Web.Routing.PublishedContentRequestEngine.PrepareRequest() +107
       Umbraco.Web.UmbracoModule.ProcessRequest(HttpContextBase httpContext) +361
       Umbraco.Web.UmbracoModule.&lt;Init&gt;b__8(Object sender, EventArgs e) +80
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +141
       System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +71
  • Nigel Wilson 904 posts 1959 karma points
    Aug 10, 2018 @ 17:59
    Nigel Wilson

    Hi there

    Is it worth updating the umbracoReservedPaths in the appSettings in the web.config with your base url ?



  • manila 217 posts 479 karma points
    Aug 15, 2018 @ 06:49

    It might have worked as the change to api routing made a difference (see my reply below), I'll check this. Thanks

  • Jon R. Humphrey 164 posts 453 karma points c-trib
    Aug 10, 2018 @ 23:38
    Jon R. Humphrey


    Apologies as I'm not 100% sure this will help but in the code snippets you showed:

    function getProducts() {
        var response; 
        $.getJSON("/api/Product").done( function (data) { 
            response = $.map(data, function (item) { 
                return { label: item.Name + ' (' + item.Code + ')' }; 
        return response; 

    but then in the API controller, you're asking for

    return searcher.GetResults();

    While you've not shown the rest of your code, and that's fine - are you 100% sure you're trying to hit the right endpoint?

    Happy to chat, look forward to your response!

    Kind regards, Jon

  • manila 217 posts 479 karma points
    Aug 15, 2018 @ 06:47

    Hi, The content of GetResults() is irrelevant in this moment as the containing method does not even get hit.

    I have solved this by changing the api routing, seee the solution here:

    Although I'm struggling to get the response on the ks site in my project. It displays well in the webapi template though so the api method is working, I just have no idea while the response is not passed through to the calling project, see the other thread:

  • suman 25 posts 95 karma points
    Aug 14, 2018 @ 12:33

    Hi Manila,

    Can you try this,

    Your controller should inherit from "UmbracoApiController". And your $.getJSON("umbraco/api/Product")

  • manila 217 posts 479 karma points
    Aug 15, 2018 @ 06:48

    Thanks suman but this is not a solution, I don't use umbraco api and I won't in this project so there is no reason to load the whole bunch of umbraco dependencies just to perform a get on the other project.

Please Sign in or register to post replies

Write your reply to: