CuriousCharlie
CuriousCharlie

Reputation: 27

NET core webapi: Why am I getting a 404 with this specific API request?

I have this request

    [HttpPost("Authenticate/{deviceIdentifier}")]
    public async Task<ActionResult<ServiceResponse<AuthorizedDoorsDto>>> Authenticate(Guid deviceIdentifier)
    {
        Guid id = Guid.Parse(User.Claims.FirstOrDefault(d => d.Type == ClaimTypes.NameIdentifier).Value);
        return Ok(await mainService.Authenticate(id, deviceIdentifier));
    }

I'm testing this with Postman and I'm sending this request:

https://localhost:5002/Main/Authenticate?deviceIdentifier=bd78209e-e3a0-4576-a17c-832838ce6495

but I'm getting a 404.

I've another requestin the same controller: this one

    //For debugging
    [HttpGet("GetAll")]
    public async Task<ActionResult<Device>> GetAll()
    {
        Guid id = Guid.Parse(User.Claims.FirstOrDefault(d => d.Type == ClaimTypes.NameIdentifier).Value);
        return Ok(await mainService.GetDevice(id));
    }

and it's working fine. So I don't get what is wrong with the first one.

Upvotes: 0

Views: 125

Answers (2)

Arnoldo Perozo
Arnoldo Perozo

Reputation: 1

Remove the {deviceIdentifier} Parameter from your request path

[HttpPost("Authenticate/{deviceIdentifier}")]

Upvotes: 0

Rafael Biz
Rafael Biz

Reputation: 463

The request returns 404 because the endpoint expects deviceIdentifier argument to be a Path Parameter instead of a Query Parameter.

In this case, you should either change the request url to https://localhost:5002/Main/Authenticate/bd78209e-e3a0-4576-a17c-832838ce6495 or remove this argument from the route to [HttpPost("Authenticate")].

Upvotes: 2

Related Questions