Copied to clipboard

Flag this post as spam?

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


  • seanrock 262 posts 483 karma points
    Jan 02, 2024 @ 11:09
    seanrock
    0

    UmbracoAuthorizedApiController unsupported media type

    Hi

    re: umbraco v12

    I've got a controller to handle some backoffice member actions. I'm using UmbracoAuthorizedApiController as the base class for my controller and a simple end point that has a guid as its only parameter.

    I'm calling the endpoint using $.ajax (post) from the angular controller but i'm getting an unsupported media error.

    I've tried replacing the simple guid parameter with a class with the guid as a property of that class as I've seen suggested in some other posts but no joy.

    Any ideas?

    Thanks.

  • Garðar Þorsteinsson 119 posts 566 karma points
    Jan 02, 2024 @ 11:54
    Garðar Þorsteinsson
    0

    Hi,

    You are probably missing [FromBody] attribute

    //[FromBody]: Indicates that a parameter should be deserialized from the request body, typically used in POST and PUT requests.
    //[FromQuery]: Indicates that a parameter should be taken from the request's query string.
    //[FromRoute]: Indicates that a parameter should be taken from the route data.
    //[FromForm]: Indicates that a parameter should be taken from the Form data.
    [HttpPost]
    [Produces("application/json")]
    [Route("items/{id:Int}")]
    public async Task<ActionResult<IEnumerable<string>>> GetItems([FromBody] ApiRequest req)
    {
        return Ok();
    }
    
  • seanrock 262 posts 483 karma points
    Jan 02, 2024 @ 13:24
    seanrock
    0

    Hi

    Actually I did have that but I changed stuff around and it started working, i probably mispelled something :D

    Thanks.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies