Home > Enterprise >  webapi end point is reached, but all parameters are empty
webapi end point is reached, but all parameters are empty

Time:11-06

I have the following end point :

    [HttpGet("/{auditReviewId}/{actioneeId?}/{entries?}")]
    public IEnumerable<AuditReviewActionDto> GetAuditReviewActions(int auditReviewId, int? actioneeId = null, int? entries = null)

and I call it the following way using HttpClient

var client = LocalHttpClient.CreateClient("UarBase");

var response = client.GetAsync("api/AuditDashboard/GetAuditReviewActions?auditReviewId="   logId   "&actioneeId="   SelectedKey   "&entries="   Limit).Result;

It doesn't matter what I set LogId, SelectedKey or Limit to, when I hit the endpoint they are always empty.

CodePudding user response:

By setting the HttpGet with [HttpGet("/{auditReviewId}/{actioneeId?}/{entries?}")], you're specifying your inputs as route parameters, but then you're passing them as query parameters.

If you'd like to pass the parameters via the query, remove them from your route (just use [HttpGet] or just supply the base route), and then tag each of your method inputs with a [FromQuery] attribute to designate they come from query parameters.

  • Related