Copied to clipboard

Flag this post as spam?

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


  • AbsolutelyN 18 posts 174 karma points
    Nov 20, 2018 @ 14:26
    AbsolutelyN
    0

    How do you add a custom route for UmbracoAuthorizedApiController?

    Hi

    I'm trying to call/post to a UmbracoAuthorizedApiController from a custom backend control with the following signature.

    public HttpResponseMessage VariantOptionsAreAvailable(int productId, int variantId, int[][] options) { .... return new HttpResponseMessage(HttpStatusCode.OK); }

    When called I get a 404. I can't figure out how to create a custom route ... I get RouteTable does not exist in current context from custom ApplicationEventHandler class.

    Using Umbraco 7.12.4

    Never used WebApi so am obviously getting this wrong ... whats the best way to approach posting some data to a UmbracoAuthorizedApiController?

    Any thoughts much appreciated - thank you.

  • Dan Diplo 1463 posts 5638 karma points MVP 3x c-trib
    Nov 20, 2018 @ 17:08
    Dan Diplo
    0

    Do you need to create a custom route? API controllers are automatically routed for you. See https://our.umbraco.com/documentation/Reference/Routing/Authorized/

  • AbsolutelyN 18 posts 174 karma points
    Nov 20, 2018 @ 17:30
    AbsolutelyN
    0

    That's a good point, I think I was assuming it must need a custom route as I just can't get it to call the api. UmbracoAuthorizedApiController works fine on other simpler methods.

    If I change it to a surfaceController rather than a UmbracoAuthorizedApiController it just works perfectly (as below).

        [HttpPost]
        public bool VariantOptionsAreAvailable(int productId, int variantId, int[][] options)
        {
            return ....
        }
    
  • Dan Diplo 1463 posts 5638 karma points MVP 3x c-trib
    Nov 21, 2018 @ 12:31
    Dan Diplo
    0

    So are you calling it using the following route:

    /umbraco/backoffice/api/controllername/VariantOptionsAreAvailable
    

    If I were you'd I'd try calling it without any parameters by both GET and then POST to determine if that works. Maybe help you narrow down the issue.

Please Sign in or register to post replies

Write your reply to:

Draft